Changes between Version 71 and Version 72 of ExplicitCallStack


Ignore:
Timestamp:
Apr 30, 2008 3:41:02 PM (7 years ago)
Author:
igloo
Comment:

Add another alternative

Legend:

Unmodified
Added
Removed
Modified
  • ExplicitCallStack

    v71 v72  
    7979}}}
    8080How realistic this is, I have no idea... but sounds good.
     81
     827. This is similar to numbers 2-4 above, but rather than having an implicit stack built up we annotate all the functions whose position we don't care about, and we are told the position of the most recent function which doesn't have such an annotation. Suppose `location` is a magic variable of a datatype `Location`, which might include source position, source span, lexical address (by which I mean, for `foo = let x = location in ...`, something like `["Main", "foo", "x"]`), and anything else that might be useful. Then
     83{{{
     84undefinedFunction = error ("Undefined here: " ++ showLocation location)
     85}}}
     86would desugar to
     87{{{
     88undefinedFunction = error ("Undefined here: " ++ showLocation (Loc 3 ...)
     89}}}
     90However, for `assert`, we want the location of the assertion, not the
     91assertion function. So we annotate `assert` with a pragma to indicate that
     92it is the location of the caller that we care about, so
     93{{{
     94{-# INVISIBLE_LOCATION assert #-}
     95assert True  _ x = x
     96assert False s _ = error ("Assert failed at " ++
     97                          showLocation location ++ ": " ++ s)
     98
     99{-# INVISIBLE_LOCATION fooAssert #-}
     100fooAssert b s x = assert b ("Foo: " ++ s) x
     101
     102fun = fooAssert myBool "what myBool tests" myResult
     103}}}
     104would desugar to
     105{{{
     106{-# INVISIBLE_LOCATION assert #-}
     107assert _ True  _ x = x
     108assert l False s _ = error ("Assert failed at " ++
     109                            showLocation l ++ ": " ++ s)
     110
     111{-# INVISIBLE_LOCATION fooAssert #-}
     112fooAssert l b s x = assert l b ("Foo: " ++ s) x
     113
     114fun = fooAssert (Loc 10 ...) myBool "what myBool tests" myResult
     115}}}
     116i.e. wherever you see `assert` or `fooAssert` you apply your location as
     117the first argument, unless you are yourself at an invisible location in
     118which case you just pass along your first argument.
    81119
    82120== Open questions ==