Commit Graph

731 Commits

Author SHA1 Message Date
practicalswift
8ee628fb14 Merge pull request #6408 from practicalswift/gardening-20161220
[gardening] Remove "REQUIRES: asserts". Correct Swift URL. Typos. Headers. PEP-8.
2016-12-20 18:47:42 +01:00
practicalswift
213716fb96 [gardening] Remove "REQUIRES: asserts" from fixed crashers 2016-12-20 10:06:14 +01:00
Slava Pestov
5640339439 Sema: Map types out of context when resolving inheritance clause in ITC 2016-12-19 18:49:57 -08:00
Slava Pestov
303f4bd19e Sema: resolveTypeInContext() checks all parent contexts first 2016-12-19 18:49:57 -08:00
Slava Pestov
ed19f2cbe9 AST: Fix gatherAllSubstitutions() for recent change to not adopt archetypes from context
This could lead to verifier failures on invalid nesting of
generic types in generic functions.
2016-12-19 18:49:57 -08:00
Slava Pestov
bb839c5fef Sema: Remove a couple of workarounds 2016-12-19 01:38:23 -08:00
Slava Pestov
4ed17f0f63 AST: Add a new 'isBeingValidated' flag to replace a couple of other flags
Previously, validateDecl() would check if the declaration had an
interface type and use that as an indication not to proceed.

However for functions we can only set an interface type after
checking the generic signature, so a recursive call to validateDecl()
on a function would "steal" the outer call and complete validation.

For generic types, this meant we could have a declaration with a
valid interface type but no generic signature.

Both cases were problematic, so narrow workarounds were put in
place with additional new flags. This made the code harder to
reason about.

This patch consolidates the flags and establishes new invariants:

- If validateDecl() returns and the declaration has no interface
  type and the isBeingValidated() flag is not set, it means one
  of the parent contexts is being validated by an outer recursive
  call.

- If validateDecl() returns and the declaration has the
  isBeingValidated() flag set, it may or may not have an interface
  type. In this case, the declaration itself is being validated
  by an outer recursive call.

- If validateDecl() returns and the declaration has an interface
  type and the isBeingValidated() flag is not set, it means the
  declaration and all of its parent contexts are fully validated
  and ready for use.

In general, we still want name lookup to find things that have an
interface type but are not in a valid generic context, so for this
reason nominal types and associated types get an interface type as
early as possible.

Most other code only wants to see fully formed decls, so a new
hasValidSignature() method returns true iff the interface type is
set and the isBeingValidated() flag is not set.

For example, while resolving a type, we can resolve an unqualified
reference to a nominal type without a valid signature. However, when
applying generic parameters, the hasValidSignature() flag is used
to ensure we error out instead of crashing if the generic signature
has not yet been formed.
2016-12-19 01:38:23 -08:00
Slava Pestov
45ef0f5dfb Sema: Generic types cannot witness associated type requirements
Until recently we didn't allow nested generic types at all.
In Swift 3, generic typealiases were added, and we forgot to
guard against them in witness matching, leading to a crash if
a generic typealias witnesses an associated type requirement.

Now that nested generic nominals are allowed too, add a check.

The diagnostic is not very good, but I'll revisit this later.
2016-12-18 22:34:16 -08:00
Slava Pestov
86d3828ea0 Sema: Don't recurse into validateDecl() when adding Objective-C bridgeable conformances
This catches another case where resolveType() could cause infinite
recursion. No test case, but this prevents crashers from regressing
with a subsequent patch.
2016-12-18 22:34:15 -08:00
Pavel Yaskevich
38165e266c [QoI] Strip BindOptionalExpr from assignment that discards target
Right before generating constraints for the new system,
check if there are any BindOptionalExpr in the tree which
wrap DiscardAssignmentExpr, such situation corresponds to syntax
like - `_? = <value>`, since it doesn't really make
sense to have optional assignment to discarded LValue which can
never be optional, we can remove BOE from the tree and avoid
generating any of the uncessary constraints.
2016-12-18 14:28:27 -08:00
Slava Pestov
88b54dcf51 AST: More consistent behavior of Type::subst() with missing substitutions
When SubstFlags::UseErrorTypes was on, we would return error types
if we couldn't resolve a nested type, but a missing primary parameter
would always remain unsubstituted in the result.

Now, replace primary parameters with error types also if they're
missing.
2016-12-17 16:28:19 -08:00
practicalswift
8fbcb94369 [gardening] Mark as crashing only under OS X 2016-12-17 22:33:09 +01:00
practicalswift
d02b5c5a38 [gardening] Remove "REQUIRES: no_asan" since crash case is marked fixed.
If it turns out that this crasher still needs "REQUIRES: no_asan" then it
isn't fixed and should be moved back to validation-test/compiler_crashers/
and marked with "not --crash" + "REQUIRES: asan" :-)
2016-12-17 22:33:09 +01:00
practicalswift
fe7c70f735 [gardening] Rename crasher to achieve consistent naming 2016-12-17 22:33:09 +01:00
practicalswift
8250854c21 [gardening] Re-enable fixed crasher 27618-swift-modulefile-getimportedmodules.swift 2016-12-17 22:33:09 +01:00
practicalswift
5862e199d9 [gardening] Remove REQUIRE-lines from fixed crashers. 2016-12-16 21:42:08 +01:00
Slava Pestov
2ff90611a8 Merge pull request #6321 from slavapestov/typealias-underlying-interface-type
Change the underlying type of TypeAliasDecls to an interface type
2016-12-16 01:31:31 -08:00
Slava Pestov
2c6b9f71b6 AST: Change TypeAliasDecls to store an interface type as their underlying type
- TypeAliasDecl::getAliasType() is gone. Now, getDeclaredInterfaceType()
  always returns the NameAliasType.

- NameAliasTypes now always desugar to the underlying type as an
  interface type.

- The NameAliasType of a generic type alias no longer desugars to an
  UnboundGenericType; call TypeAliasDecl::getUnboundGenericType() if you
  want that.

- The "lazy mapTypeOutOfContext()" hack for deserialized TypeAliasDecls
  is gone.

- The process of constructing a synthesized TypeAliasDecl is much simpler
  now; instead of calling computeType(), setInterfaceType() and then
  setting the recursive properties in the right order, just call
  setUnderlyingType(), passing it either an interface type or a
  contextual type.

  In particular, many places weren't setting the recursive properties,
  such as the ClangImporter and deserialization. This meant that queries
  such as hasArchetype() or hasTypeParameter() would return incorrect
  results on NameAliasTypes, which caused various subtle problems.

- Finally, add some more tests for generic typealiases, most of which
  fail because they're still pretty broken.
2016-12-15 22:46:15 -08:00
Robert Widmann
443bc682f6 Actually improve recovery when parsing bogus expressions
The crashes fixed appeared at first to be related to IfConfigStmt
parsing, but are in reality symptoms of being too lax in what we accept
when parsing of sub-expressions fail.

Optional type annotation parsing used to propagate failures before it
was patched to ‘recover’ with an AnyPattern.  Instead, we’ll just hit
the error path for parsing in the main expressions because what is here
now isn’t a reasonable thing to return.

#selector parsing assumed that the current token it was at after
consuming up to a right-brace wasn’t bogus.  Instead, if we’ve got
here, we may as well just return a loc we know is valid: PreviousLoc.
2016-12-15 19:08:26 -05:00
Doug Gregor
6f0ad958af Merge pull request #6299 from xedin/crasher-28575
[QoI] Look through LValueness of the type when trying to coerce from/to UnresolvedType
2016-12-15 08:51:52 -08:00
practicalswift
286d4d7581 Mark as fixed. 2016-12-15 10:57:04 +01:00
Pavel Yaskevich
be4bea917b [QoI] Look through LValueness of the type when trying to coerce from/to UnresolvedType 2016-12-14 23:14:53 -08:00
Slava Pestov
a52ad69c1e Sema: Avoid validateDecl() recursion through the 'unsupported existential' check
When type-checking decls, we would ensure they don't reference
existential types formed from protocols with associated types
or 'Self' requirements. However this check was done in both
'stage 1' and 'stage 2', which meant it would be called
recursively from validateDecl().

Fix this by performing the check only once at the end of
type checking a source file.
2016-12-12 20:41:03 -08:00
Rintaro Ishizaki
42ebd38c29 [Parse] Skip non-case-label statements in switch (#6215) 2016-12-13 03:37:09 +09:00
Pavel Yaskevich
646638d214 [TypeChecker] Add retired constraints to the front of the list in SolverScope
Since retired constraints are re-added back to the circulation in LIFO
order, make sure that all of the constraints are added to the front of
SolverScope::retiredConstraints list.
2016-12-11 21:44:19 -08:00
practicalswift
a3ccac27db [gardening] Remove "REQUIRES: asserts" from fixed crashers. 2016-12-11 00:50:26 +01:00
Slava Pestov
ddd19c6207 Sema: Hacky fix for infinite recursion if a class inherits from itself
This seems to come up a lot; we need to consolidate and clean up
inheritance circularity breaks.
2016-12-09 20:12:29 -08:00
Slava Pestov
9a65745f9b AST: Robustness fix 2016-12-09 20:12:28 -08:00
Slava Pestov
4c0d1488e2 Sema: Don't add implicit constructors when checking inheritance clause
This leads to some bad recursion through validateDecl(), even
when called from the ITC. We already had machinery to add
implicit constructors later, it just had to be extended to
do it for the superclass as well.
2016-12-09 20:12:28 -08:00
Slava Pestov
e063e8297c Sema: Some fixes for the ITC
- In functions called from resolveType(), consistently
  use a Type() return value to indicate 'unsatisfied
  dependency', and ErrorType to indicate failure.

- Plumb the unsatisfiedDependency callback through the
  resolution of the arguments of BoundGenericTypes, and
  also pass down the options.

- Before doing a conformance check on the argument of a
  BoundGenericType, kick off a TypeCheckSuperclass request
  if the type in question is a class. This ensures we don't
  recurse through NominalTypeDecl::prepareConformanceTable(),
  which wants to see a class with a valid superclass.

- The ResolveTypeOfDecl request was assuming that
  the request was satisfied after calling validateDecl().
  This is not the case when the ITC is invoked from a
  recursive call to validateDecl(), hack this up by returning
  *true* from isResolveTypeDeclSatisfied(); otherwise we
  assert in satisfy(), and we can't make forward progress
  in this case anyway.

- Fix a bug in cycle breaking; it seems if we don't invoke
  the cycle break callback on all pending requests, we end
  up looping forever in an outer call to satisfy().

- Remove unused TR_GlobalTypeAlias option.
2016-12-09 17:36:49 -08:00
practicalswift
5714126903 [gardening] Remove "REQUIRES: asserts" from fixed crasher. 2016-12-09 21:46:19 +01:00
Slava Pestov
58d4a07fa6 Sema: Clean up accessor synthesis
- Remove unnecessary calls to validateDecl() and typeCheckDecl()
- Simplify the logic around synthesizing materializeForSet
2016-12-08 23:22:16 -08:00
Jordan Rose
49e6c06eef [validation-test] Remove "REQUIRES: asserts" from /fixed/ crash cases. (#6156) 2016-12-08 19:06:32 -08:00
Pavel Yaskevich
f1be35c178 [QoI] Add return after coercing to TupleElementExpr in ExprRewriter::coerceToType
Adds missing return statement for coercions which extract a single
element from a tuple aka tuple-to-scalar conversions in ExprRewriter::coerceToType.
2016-12-08 02:05:46 -08:00
Doug Gregor
aa3d024f8d [Type checker] Eliminate reuse of contextual archetypes in nested generics.
Prior to this change, nested generics always reused the archetypes of
either enclosing contexts. For example, given:

  struct X<T> {
    func f<U>(_: U) { }
  }

The generic environment for X.f(_:) would use the same archetype for T
as the generic environment X. This reuse allowed some sloppiness
within the implementation---one did not necessarily have to remember
to substitute entities that came from an immediate outer context---but
caused an annoying limitation that nested generics could not add any
constraints to an archetype that came from an outer scope. Worse, the
compiler would not always diagnose this as an error, leading to
constraints being silently dropped, as in the example from the
referenced radar (see the change to
test/Generics/associated_types.swift).

Now, build a fresh generic environment for each context that
introduces new generic parameters, with archetypes that are completely
separate from the archetypes of enclosing contexts.

Fixes rdar://problem/29207581.
2016-12-07 08:10:12 -08:00
Xi Ge
21927755ae [test] Disable flaky test: 28562-swift-typebase-getcanonicaltype.swift (#6111) 2016-12-06 15:39:47 -08:00
Xi Ge
4796da0457 [test] Mark compiler_crashers/28562-swift-typebase-getcanonicaltype.swift as fixed. (#6107) 2016-12-06 13:02:19 -08:00
practicalswift
d0021713d2 [gardening] Remove duplicate file. 2016-12-06 20:21:19 +01:00
Slava Pestov
63178e84d2 AST: Improve robustness with invalid nesting of extensions in generic context
Extensions cannot capture generic parameters from outer contexts.
Their generic parameter list does not point to the outer
parameter list, the signature does not contain outer parameters
and they do not appear in the extension's generic environment.

Furthermore, the depth/index of the extension's parameters may
clash with outer parameters, which would break all kinds of
invariants.

This patch changes these DeclContext methods to return false or
nullptr even if an extension is contained in a generic context:

- isGenericContext()
- getGenericParamsOfContext()
- getGenericSignatureOfContext()
- getGenericEnvironmentOfContext()
2016-12-06 09:41:30 -08:00
Slava Pestov
81fad09b8d Sema: Nominal types nested inside protocols are not requirements 2016-12-06 09:41:30 -08:00
Slava Pestov
fdaa886065 Sema: Rework resolveTypeInContext()
Separate the "find the correct context" part from "substitute in the
base type" part. The former can go away completely after a bit of
refactoring.
2016-12-06 09:39:28 -08:00
Doug Gregor
6c7277be2c [Type checker] Work around issues with badly broken generic code.
The GenericTypeOrArchetypeResolver changes are effectively porting
some existing hacks from the now-dead
PartialGenericTypeOrArchetypeResolver, which dodges some regressions
in the compiler-crashers suite and fixes 11 new crashers. There is
undoubtedly a more principled approach to fix these problems, most of
which now step from recursively looking for a generic environment that
isn't there, but doing so requires improvements to our name lookup.
2016-12-05 22:44:24 -08:00
swift-ci
70d818b479 Merge pull request #6091 from xedin/cs_crashers 2016-12-05 21:33:18 -08:00
Xi Ge
1570f8e4f1 Fixing IDE/crashers/091-swift-typechecker-computedefaultaccessibility.swift (#6084) 2016-12-05 20:52:07 -08:00
Pavel Yaskevich
712052bc9a [QoI] Mark inactive constraints as retired after removing
This makes sure that removed constraints are returned back to the
system after current run, otherwise only constraint graph would
get them back since it has its own scope.
2016-12-05 20:50:32 -08:00
David Farler
25e623addb Don't resolve a generic type parameter type from null environments
The generic environment of a GenericTypeToArchetypeResolver may be
`nullptr`, as returned by DeclContext::getGenericEnvironmentOfContext,
during prechecking of closure expressions at the necessarily non-generic
top level.

Fixes a couple of crashers.
2016-12-05 19:34:02 -08:00
Janek Spaderna
3a95673aa3 [Sema] Don't crash on @IBDesignable extensions wit no type 2016-12-05 18:33:54 +01:00
Slava Pestov
1a991da16d AST: Assign interface types to ParamDecls
First, ensure all ParamDecls that are synthesized from scratch are given
both a contextual type and an interface type.

For ParamDecls written in source, add a new recordParamType() method to
GenericTypeResolver. This calls setType() or setInterfaceType() as
appropriate.

Interestingly enough a handful of diagnostics in the test suite have
improved. I'm not sure why, but I'll take it.

The ParamDecl::createUnboundSelf() method is now only used in the parser,
and no longer sets the type of the self parameter to the unbound generic
type. This was wrong anyway, since the type was always being overwritten.
This allows us to remove DeclContext::getSelfTypeOfContext().

Also, ensure that FuncDecl::getBodyResultTypeLoc() always has an interface
type for synthesized declarations, eliminating a mapTypeOutOfContext()
call when computing the function interface type in configureInterfaceType().

Finally, clean up the logic for resolving the DynamicSelfType. We now
get the interface or contextual type of 'Self' via the resolver, instead
of always getting the contextual type and patching it up inside
configureInterfaceType().
2016-12-04 00:02:21 -08:00
Doug Gregor
c98295357c [Archetype builder] Simplify handling of typealiases in protocols.
PotentialArchetype::getNestedType() was effectively reimplementing a
simplified form of mapTypeOutOfContext(), missing some cases in the
process. Just use mapTypeOutOfContext() and resolveArchetype(). While
here, stop re-implementing the addSameType* operations; just call them
directly. With these changes, we no longer need the "typealias in
protocol is too complex" diagnostic.

Eliminates another use of getSelfTypeInContext().
2016-12-02 15:31:04 -08:00
swift-ci
8be4df4bae Merge pull request #6011 from DougGregor/lazy-nested-types 2016-12-01 21:05:13 -08:00