Coder Social home page Coder Social logo

cassertte.jl's Introduction

Cassertte.jl

Cassertte is an Assertion library, providing @Cassertte: an @assert replacement that allows eliminating the entire expression in the assertion body.

This is similar to the way the C/C++ <cassert> library disables the entire assert(expression) when #define NDEBUG is set.

I've currently opted for @Cassertte statements to be disabled by default, only evaluating their argument expressions when called via @withCassertte.

Cassertte is built using Casette.jl, and is implemented by recompiling your provided function with the @Cassertte expr statements re-injected.

    @Cassertte length(unique(elements)) == 10

An @assert replacement that only evaluates its argument expr when called via @withCassertte.

@Cassertte is disabled by default, and can be enabled in calling code via @withCassertte.
Importantly, the _entire expression_ is eliminated. This frees you to check expensive
calculations in your assert statement. But of course, it means that you should never
depend on the side effects of an expression within a @Cassertte.

To run your code with all @Cassertte statements enabled, use @withCassertte:
```
    @withCassertte foo(1,2)
```

Installation

Cassette is built with Toggles.jl, which you should install for this to work:

(v1.0) pkg> add https://github.com/NHDaly/Toggles.jl
(v1.0) pkg> add https://github.com/NHDaly/Cassertte.jl

cassertte.jl's People

Contributors

nhdaly avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

juliatagbot

cassertte.jl's Issues

Code bloat when using `@withCassertte`

I've opened JuliaLabs/Cassette.jl#84 for this same issue.

julia> @code_native @withCassertte 5+5 shows a huge blowup in code size compared with regular 5+5:

julia> @code_native @withCassertte 5+5
    .section    __TEXT,__text,regular,pure_instructions
; Function @withCassertte {
; Location: Cassertte.jl:35
    pushl   %ebp
    decl    %eax
    movl    %esp, %ebp
    incl    %ecx
    pushl   %edi
    incl    %ecx
    pushl   %esi
    incl    %ecx
    pushl   %ebp
    incl    %ecx
    pushl   %esp
    pushl   %ebx
    decl    %eax
    andl    $-32, %esp
    decl    %eax
    subl    $160, %esp
    decl    %eax
    movl    %esi, %ebx
    vxorps  %xmm0, %xmm0, %xmm0
    vmovaps %ymm0, 64(%esp)
    decl    %eax
    movl    $0, 96(%esp)
    decl    %eax
    movl    %ebx, 128(%esp)
    decl    %eax
    movl    $61493632, %eax         ## imm = 0x3AA5180
    addl    %eax, (%eax)
    addb    %al, (%eax)
    vzeroupper
    calll   *%eax
    decl    %ecx
    movl    %eax, %esi
    decl    %eax
    movl    $6, 64(%esp)
    decl    %ecx
    movl    (%esi), %eax
    decl    %eax
    movl    %eax, 72(%esp)
    decl    %eax
    leal    64(%esp), %eax
    decl    %ecx
    movl    %eax, (%esi)
    decl    %esp
    movl    16(%ebx), %esp
    decl    %eax
    movl    $61271328, %ebx         ## imm = 0x3A6ED20
    addl    %eax, (%eax)
    addb    %al, (%eax)
    decl    %eax
    movl    $139887888, %edi        ## imm = 0x8568510
    addl    %eax, (%eax)
    addb    %al, (%eax)
    calll   *%ebx
    decl    %ecx
    movl    %eax, %edi
    decl    %esp
    movl    %edi, 96(%esp)
    decl    %eax
    movl    $139887952, %edi        ## imm = 0x8568550
    addl    %eax, (%eax)
    addb    %al, (%eax)
    calll   *%ebx
    decl    %eax
    movl    %eax, %ebx
    decl    %eax
    movl    %ebx, 88(%esp)
; Function esc; {
; Location: essentials.jl:462
; Function Type; {
; Location: boot.jl:221
    decl    %eax
    movl    $187084000, %eax        ## imm = 0xB26ACE0
    addl    %eax, (%eax)
    addb    %al, (%eax)
    decl    %eax
    movl    %eax, 24(%esp)
    decl    %esp
    movl    %esp, 32(%esp)
    decl    %ecx
    movl    $61292176, %ebp         ## imm = 0x3A73E90
    addl    %eax, (%eax)
    addb    %al, (%eax)
    decl    %esp
    leal    24(%esp), %esp
    xorl    %edi, %edi
    movl    $2, %edx
    decl    %esp
    movl    %esp, %esi
    incl    %ecx
    calll   *%ebp
    decl    %eax
    movl    %eax, 80(%esp)
;}}
    decl    %eax
    movl    $187083952, %ecx        ## imm = 0xB26ACB0
    addl    %eax, (%eax)
    addb    %al, (%eax)
    decl    %eax
    movl    %ecx, 24(%esp)
    decl    %esp
    movl    %edi, 32(%esp)
    decl    %eax
    movl    $139888080, %ecx        ## imm = 0x85685D0
    addl    %eax, (%eax)
    addb    %al, (%eax)
    decl    %eax
    movl    %ecx, 40(%esp)
    decl    %eax
    movl    %ebx, 48(%esp)
    decl    %eax
    movl    %eax, 56(%esp)
    xorl    %edi, %edi
    movl    $5, %edx
    decl    %esp
    movl    %esp, %esi
    incl    %ecx
    calll   *%ebp
    decl    %eax
    movl    %eax, 80(%esp)
    decl    %eax
    movl    $187097240, %ecx        ## imm = 0xB26E098
    addl    %eax, (%eax)
    addb    %al, (%eax)
    decl    %eax
    movl    %ecx, 24(%esp)
    decl    %eax
    movl    $139888144, %ecx        ## imm = 0x8568610
    addl    %eax, (%eax)
    addb    %al, (%eax)
    decl    %eax
    movl    %ecx, 32(%esp)
    decl    %eax
    movl    %eax, 40(%esp)
    xorl    %edi, %edi
    movl    $3, %edx
    decl    %esp
    movl    %esp, %esi
    incl    %ecx
    calll   *%ebp
    decl    %eax
    movl    72(%esp), %ecx
    decl    %ecx
    movl    %ecx, (%esi)
    decl    %eax
    leal    -40(%ebp), %esp
    popl    %ebx
    incl    %ecx
    popl    %esp
    incl    %ecx
    popl    %ebp
    incl    %ecx
    popl    %esi
    incl    %ecx
    popl    %edi
    popl    %ebp
    retl
;}

julia> @code_native 5+5
    .section    __TEXT,__text,regular,pure_instructions
; Function + {
; Location: int.jl:53
    decl    %eax
    leal    (%edi,%esi), %eax
    retl
;}
; Function <invalid> {
; Location: int.jl:53
    nopw    %cs:(%eax,%eax)
;}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.