variable has the must-be-materializable bit set if the old one does.
When assigning a fixed type to a type variable that must be
materializable, transfer the bit to any type variables within the fixed
type, as appropriate.
Add Options field to SavedTypeVariableBinding to save/restore type
variable options during solution.
<rdar://problem/21026806> Propagate MustBeMaterializable bit among type variables appropriately
Swift SVN r28883
Add a new option, TVO_MustBeMaterializable, to
TypeVariableType::Implementation, and set it for type variables
resulting from opening a generic type. This solution isn't complete (we
don't yet copy the non-materializable bit on unification of type
variables, and it's possible to bind a must-be-materializable type
variable to a type with type variables that later get bound to
non-materializable types) but it addresses all reported crashes for this
issue.
<rdar://problem/20807269> Crash in non-materializable type
Swift SVN r28792
This just deletes some code out of matchCallArguments to make sure that CSApply
and CSSimplify do the same argument matching. This code presumably
dated to a period of time when the stuff after it was just for error recovery,
but now we do argument reordering matching stuff after this point.
Swift SVN r28670
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".
Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).
Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.
Swift SVN r28284
checking checked cast via bridging. It prevented bridging upcasts using
'as!' from typechecking; we should emit an 'as!'->'as' warning instead.
Also, use ExplicitConversion constraint instead of Conversion when
determining whether a checked cast can be carried out unconditionally.
This matches the constraint used after applying the 'as!'->'as' fixit.
(Also, fix the error that was responsible for breaking
the expr/cast/bridged.swift test.)
<rdar://problem/19813772>
Swift SVN r28034
checking checked cast via bridging. It prevented bridging upcasts using
'as!' from typechecking; we should emit an 'as!'->'as' warning instead.
Also, use ExplicitConversion constraint instead of Conversion when
determining whether a checked cast can be carried out unconditionally.
This matches the constraint used after applying the 'as!'->'as' fixit.
<rdar://problem/19813772>
Swift SVN r28028
ConstraintSystem::dump to ConstraintSystem::print for
consistency with other parts of the compiler. Enhance
CS::print to print the ID # of a Type Variable, so you
don't have to count them to realize that you're looking
at typevar #13
Swift SVN r27874
In addition to being better for performance in these cases, this disables the "self."
requirement in these blocks. {}() constructs are often used to work around statements
that are not exprs in Swift, so they are reasonably important.
Fixing this takes a couple of pieces working together:
- Add a new 'extraFunctionAttrs' map to the ConstraintSystem for solution
invariant function attributes that are inferred (like @noescape).
- Teach constraint simplification of function applications to propagate
@noescape between unified function types.
- Teach CSGen of ApplyExprs to mark the callee functiontype as noescape
when it is obviously a ClosureExpr.
This is a very limited fix in some ways: you could argue that ApplyExpr should
*always* mark its callee as noescape. However, doing so would just introduce a
ton of function conversions to remove it again, so we don't do that.
Swift SVN r27723
This reverts commit r27576.
(In some cases of catastrophic error recovery, ctor types may still be null during constraint solving, so it was wrong of me to assume otherwise.)
Swift SVN r27599
This reverts commit r27568 to unblock the buildbot. It regressed three
compiler crashers:
Swift :: compiler_crashers_fixed/0367-llvm-errs.swift
Swift :: compiler_crashers_fixed/1769-getselftypeforcontainer.swift
Swift :: compiler_crashers_fixed/1916-swift-nominaltypedecl-getdeclaredtypeincontext.swift
Swift SVN r27576
- When inferring 'throws' for a closure function type, look inside of catchless do blocks for 'try' expressions.
- When simplifying overload constriants for applications of throwing initializers, the bound member type of the initializer should also be marked as throwing.
(Not doing so would cause us to incorrectly reject the overload.)
Swift SVN r27568
Fix crashes when type-checking ErrorType dynamic casts when NSError isn't available. Split the ErrorType execution tests into separate units for bridging and non-bridging, so that we get better coverage of this situation in both ObjC and non-ObjC builds. Fixes rdar://problem/20585210.
Swift SVN r27556
The post-type-checking error that was here is arguably better QoI, but it is causing ambiguities that break the non-ObjC-compatible build in the stdlib. We shouldn't even attempt these conversions if there's no runtime support to back them up.
Swift SVN r27407
A non-throwing function can be a trivial subtype of a throwing
function. Encode this rule more directly, introduce some additional
tests to ensure that we get the behavior right where we need exact
matches, and add a failure kind with custom diagnostic for cases where
function types mismatch due to 'throws'.
Swift SVN r27255
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements". Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).
At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].
NFC.
Swift SVN r26894
This pushes tuple pattern labels forward:
- Actually record them in TuplePatternElt.
- Remove the tuple shuffle ban that prevents some cases
(e.g. the one in the radar) of a tuple with labels being shuffled
onto a tuple without labels.
- Remove dead code enabled by removing the restriction.
Swift SVN r26852
UnsafeMutablePointer<Void>, don't bind $T1 to Void. This fixes an
unintentional dependency on the order in which constraints are visited
by the solver.
Fix some resulting underconstrained expressions in the stdlib.
<rdar://problem/19835413> Reference to value from array changed
Swift SVN r25921
when it is the favored constraint of a disjunction.
This allows 'ns ?? "str" as String as String' to typecheck where ns is
an NSString. This does not regress the relevant test for 17962491.
<rdar://problem/20029786> Swift compiler sometimes suggests changing "as!" to "as?!"
Swift SVN r25910
Update the locator when matching optional types in parallel fashion.
This causes the simplifyLocator() call to fail to simplify the locator
completely, and avoids the bogus diagnostic.
<rdar://problem/19836341> Incorrect fixit for NSString? to String? conversions
Swift SVN r25596
John pointed out that messing with the type checker's notion of "subtype"
is a bad idea. Instead, we should just have a separate check for ABI
compatibility...and eventually (rdar://problem/19517003) just insert the
appropriate thunks rather than forcing the user to perform the conversion.
I'm leaving all the tests as they are because I'm adding a post-type-checking
diagnostic in the next commit, and that should pass all the same tests.
Part of rdar://problem/19600325
Swift SVN r25116
Penalize solutions that involve 'as' -> 'as!' changes by recording a Fix
when simplifying the corresponding checked-cast constraint.
<rdar://problem/19724719> Type checker thinks "(optionalNSString ?? nonoptionalNSString) as String" is a forced cast
Swift SVN r25061
This re-applies r24987, reverted in r24990, with a fix for a spuriously-
introduced error: don't use a favored constraint in a disjunction to avoid
applying a fix. (Why not? Because favoring bubbles up, i.e. the
/disjunction/ becomes favored even if the particular branch is eventually
rejected.) This doesn't seem to affect the outcome, though: the other
branch of the disjunction doesn't seem to be tried anyway.
Finishes rdar://problem/19600325
Swift SVN r25054
let x: Int? = 4 as Int // okay
let f: (Int) -> Void = { (x: Int?) -> Void in println(x) } // error!
As part of this, remove an invalid "protection" of value-to-optional
conversions that involve T? -> T??. Unfortunately, this results in an
ambiguity in the following code:
var z: Int?
z = z ?? 42
Both of our overloads for ?? here require one value-to-optional conversion,
and the overload preference isn't conclusive. (Turns out (T?, T) and
(U?, U?) can be unified as T=U or as T=U?.) The best thing to do would be
to take our solved T=Int binding into account, but the type checker isn't
set up to do that at the moment.
After talking to JoeP, I ended up just hardcoding a preference against
the (T?, T?) -> T? overload of ??. This is only acceptable because both
overloads have the same result, and I'll be filing another Radar to
remove this hack in the future.
Part of rdar://problem/19600325
Swift SVN r25045
And even if we don't suggest wrapping in a closure (say, because there's
already a closure involved), emit a more relevant diagnostic anyway.
(Wordsmithing welcome.)
Wrapping a function value in a closure essentially explicitly inserts a
conversion thunk that we should eventually be able to implicitly insert;
that's rdar://problem/19517003.
Part of rdar://problem/19600325
Swift SVN r24987
For example, we used to have an implicit conversion from NSString to
String, but it was removed. Provide a Fix-It that suggests "as!
String". Fixes <rdar://problem/19551164>.
Swift SVN r24948
These haven't ever been safe in Swift's development because they require
generating thunks, and we currently don't do that. However, we were letting
existential conversions slip through the cracks because we consider them
subtypes, so that /metatype/ conversions work correctly. To be concrete:
"let _: Any.Type = Int.self" is okay.
"let _: (Int) -> Void = { (_: Any) -> Void in return }" is not.
We should implement this some day; that's rdar://problem/19517003.
This produces some lousy error messages, which I intend to fix soon.
Part of rdar://problem/19600325
Swift SVN r24915
Previously, trailing closures would try to match the first parameter
of (possibly optional) function type that didn't seem to have an
argument already, but in practice this broke when there were
parameters with default arguments before the function parameter.
The new rule is far simpler: a trailing closure matches the last
parameter. Fixes rdar://problem/17965209.
Swift SVN r24898
When generating constraints for an 'as' expression, consider the
possibility that the code is supposed to be 'as!' instead of 'as'. Emit
the appropriate fixit if that branch of the disjunction is chosen by the
constraint solver.
This is a more comprehensive fix for <rdar://problem/19499340> than the
one in r24815.
Swift SVN r24872