Skip to content

Commit

Permalink
Add unchecked annotation to inlined body
Browse files Browse the repository at this point in the history
  • Loading branch information
jad-hamza committed Jul 28, 2021
1 parent c479ca6 commit f8227fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ trait FunctionInlining extends CachingPhase with IdentitySorts { self =>
val specced = BodyWithSpecs(tfd.fullBody)
// simple path for inlining when all arguments are values, and the function's body doesn't contain other function invocations
if (specced.specs.isEmpty && args.forall(isValue) && !exprOps.containsFunctionCalls(tfd.fullBody)) {
exprOps.replaceFromSymbols(tfd.params.zip(args).toMap, exprOps.freshenLocals(tfd.fullBody))
annotated(exprOps.replaceFromSymbols(tfd.params.zip(args).toMap, exprOps.freshenLocals(tfd.fullBody)), Unchecked)
} else {
// We need to keep the body as-is for `@synthetic` methods, such as
// `copy` or implicit conversions for implicit classes, in order to
Expand Down Expand Up @@ -119,15 +119,10 @@ trait FunctionInlining extends CachingPhase with IdentitySorts { self =>
case _ => e
}


val res = ValDef.fresh("inlined", tfd.returnType)
val inlined = addPreconditionAssertions(addPostconditionAssumption(body))

// We bind the inlined expression in a let to avoid propagating
// the @unchecked annotation to postconditions, etc.
val newBody = let(res, inlined, res.toVariable.setPos(fi)).setPos(fi)

val result = (tfd.params zip args).foldRight(newBody) {
val result = (tfd.params zip args).foldRight(inlined) {
case ((vd, e), body) => let(vd, e, body).setPos(fi)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object InliningUnchecked {

@inline def f: Int = 0

def g: Int = {
f
}.ensuring(_ == 10)

}

0 comments on commit f8227fe

Please sign in to comment.