Skip to content

Fix regression with lazy properties and add another test case [4.0] #10911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Jul 12, 2017

  • Description: When type checking an expression without applying the solution, we would set the types of anonymous closure parameters to ErrorType. This resulted in SILGen crashes because of un-typechecked AST when a lazy property was initialized by an expression containing a closure with anonymous parameters.

  • Origination: Regression from another set of fixes to 'lazy' in 4.0.

  • Tested: New test added. Also add another test for an odd behavior with 'lazy' that worked in 3.1 but we don't want to allow anymore. This second part is not really necessary for 4.0 branch, but it's just a new test.

  • Reviewed by: Pavel Yaskevich (first two patches), Mark Lacey (ASan fix)

  • Radar: rdar://problem/33219081

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov requested a review from xedin July 12, 2017 21:30
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@slavapestov
Copy link
Contributor Author

This is failing in ASan unfortunately. I'll have a corrected version soon.

…ymous closure parameters

Even if we don't apply the solution, we still end up writing
types into ParamDecls of closures contained the expression.

Make sure this is idempotent by disabling 'cleanup', which
avoids setting them to ErrorTypes, and teaching ExprCleaner
to clear out types of VarDecls.

This is a hack that will get better once the constraint
system type map stuff is further along.

Fixes <rdar://problem/33219081>.
Due to a serendipitous confluence of interesting behaviors,
Swift 3 allowed you to define a lazy property with an IUO
type, and setting the property to nil would 'reset' it,
re-evaluating the lazy getter the next time the property
was accessed.

This was not intended behavior and it no longer works,
so add a test that it no longer works.

Fixes <rdar://problem/32687168> and
<https://bugs.swift.org/browse/SR-5172>.
@slavapestov slavapestov force-pushed the raii-scrubbers-are-bad-and-should-die-4.0 branch from 9365ada to a12b3f8 Compare July 14, 2017 23:35
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 9365ada474d9aee113936ad4fb42dd2b74c2f5f3
Test requested by - @slavapestov

There are two "RAII cleaners" here:

- CleanupIllFormedExpressionRAII cleans up the Expr in its final state
- ExprCleanser walks the Expr before it is mutated and collects
  sub-expressions, then cleans those up after

The subtle difference comes into play if we started to apply the
solution (which can fail, leaving the AST in an inconsistent state)
or if preCheckExpression() modified the AST.

The latter case was causing an ASan failure because we were not
cleaning up type variables in new nodes introduced by
preCheckExpression().

Fix this by moving the preCheckExpression() call out of
solveForExpression(), so that if solveForExpression() is called
with TypeCheckExprFlags::SkipApplyingSolution, we don't mutate the
AST at all.

Sigh...

Fixes <rdar://problem/33277279>.
@slavapestov slavapestov force-pushed the raii-scrubbers-are-bad-and-should-die-4.0 branch from a12b3f8 to a0d7055 Compare July 15, 2017 00:28
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - a12b3f83b12b2c106ad61f4af7a1cdd0fcd0ca95
Test requested by - @slavapestov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants