Commit Graph

409 Commits

Author SHA1 Message Date
Doug Gregor
d40e869765 [AST Verifier] Don't verify parsed function bodies in a type-checked AST.
Eliminates an AST verifier crash on reasonable ASTs where we ended up
synthesizing the body for a function (e.g., from the Clang importer)
that we don't actually need to type-check. Fixes
rdar://problem/32774779.
2017-06-19 15:53:44 -07:00
Slava Pestov
732b215b88 Merge pull request #9413 from rintaro/ast-eliminate-ifconfigstmt
[AST] Eliminate IfConfigStmt
2017-06-16 15:39:47 -07:00
Doug Gregor
6a2b6c271f [AST] Add TypeBase::findUnresolvedDependentMemberType() and use it 3x.
NFC: Eliminate some duplicated "search for an unresolved dependent
member type" code scattered around.
2017-06-15 23:23:07 -07:00
Robert Widmann
abd5aa8e6d Rename some X-Value-related entities
* Rename coerceToMaterializableValue to coerceToRValue

* Rename isLValueType to hasLValueType to better match the
intended semantics of the member.
2017-06-14 13:18:45 -07:00
Mark Lacey
692c5590c7 Expect all expressions to have a type after type checking.
Rather than skipping expressions that have no type in post-type checking
verification, verify that they do have a type.

There is one exception to "all" expressions having a type. We serialize
the un-typechecked raw values of @objc enums, and thus after
deserialization we do not have types for these. We cannot distinguish
these in the verifier, though, so we just allow any integer literal
through without a type.
2017-06-05 09:50:52 -07:00
Mark Lacey
fb5ac6df02 [Constraint solver] Fix an issue with rewriting OpenExistentialExpr.
If we fail when doing a coercion while generating an OpenExistentialExpr
when applying a solution during type checking, make sure that the opaque
value on that OpenExistentialExpr is cleared.

We do not visit these during normal AST walks because they normally
appear in the subexpression held by the OpenExistentialExpr. In this
case, however, we replace that subexpression with an ErrorExpr which
means we will not visit the opaque value at all, so certain operations,
like setting the type on the opaque value, will never happen, and we can
run into problems later by code that assumes the type is set.

It seems reasonable to just clear these out in cases like this since
they are not reachable by any normal means.
2017-06-01 20:18:29 -07:00
Alex Hoppen
f302afc97f Unify approach to printing declaration names (#9320)
Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:25:20 -07:00
Mark Lacey
99393067cf Merge pull request #9695 from rudkx/fix-rdar32239354
Fix some issues in handling of withoutActuallyEscaping.
2017-05-17 22:17:42 -07:00
Mark Lacey
b8cc015113 Fix some issues in handling of withoutActuallyEscaping.
We need to strip inout/lvalue before casting the second parameter's type
to FunctionType.

There were also some verification issues and the fact that we weren't
allowing already-escaping closures to be passed to it (which is not
useful, but shouldn't result in an error and really awful
diagnostic). We can potentially look at diagnosing this with a warning
at some point in the future.

Fixes rdar://problem/32239354.
2017-05-17 17:13:47 -07:00
Doug Gregor
f792aeaf1a [AST] Teach the AST verifier not to deserialize generic environments.
The AST verifier was causing deserialization of generic environments,
which slows things down considerably and affects our ability to test
for laziness in deserialization. Prevent it from doing so---and only
do the extra checkig if something else deserialized the generic
environment already.

... except there are some cases where it happens through means that
are harder to control (e.g., the AST walker for patterns) that need
more thought.
2017-05-16 11:03:15 -07:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
John McCall
338825e73d Fix the emission of r-value pointer conversions to delay the
conversions and extend lifetimes over the call.

Apply this logic to string-to-pointer conversions as well as
array-to-pointer conversions.

Fix the AST verifier to not blow up on optional pointer conversions,
and make sure we SILGen them correctly.  There's still an AST bug
here, but I'll fix that in a follow-up patch.
2017-04-26 14:15:44 -04:00
John McCall
e6d52d8808 LValueToPointerExpr is dead code. RIP LValueToPointerExpr. 2017-04-25 03:01:16 -04:00
Doug Gregor
2c32f72303 [AST Verifier] Tolerate partially-validated ASTs.
We can get partially-validated ASTs when they are created by the Clang
importer, but not otherwise needed or after new code can be
introduced. Avoid doing the "checked" verification on such ASTs, to
make assertions-enabled builds more useful for testing.

This is the wrong long-term solution: the AST verifier should tolerate
partially-type-checked ASTs at a finer granularity, but doing so is a
larger project than I can take on at the moment.
2017-04-24 09:46:18 -07:00
practicalswift
a596961187 [gardening] Make parameter name comments match actual parameter names 2017-04-20 13:47:10 +02:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Slava Pestov
6580e5055f AST Verifier: Remove a usage of getExistentialTypeProtocols() 2017-04-17 17:22:29 -06:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Slava Pestov
d49f8fb6d9 AST: Introduce primitive AnyObject type
Add a 'hasExplicitAnyObject()' bit to ProtocolCompositionType
to represent canonical composition types containing '& AnyObject'.

Serialize this bit and take it into account when building
ExistentialLayouts.

Rename ProtocolCompositionType::getProtocols() to getMembers()
since it can contain classes now, and update a few usages that
need further attention with FIXMEs or asserts.

For now, nothing actually constructs these types, and they will
trigger arounds asserts. Upcoming patches will introduce support
for this.
2017-04-13 21:17:05 -07:00
Jordan Rose
730b80a8a2 [ASTVerifier] Add missing verifyCheckedBase for GenericTypeDecl.
All tests still pass, so it looks like we haven't regressed.
2017-04-13 13:46:07 -07:00
Michael Gottesman
244f1f60c4 [ast-verifier] Verify that inout_to_pointer and array_to_pointer are (almost) immediate children of an ApplyExpr argument.
Specifically we only allow it as an argument to a TupleExpr and a ParenExpr and
can have the following forms:

  (inject_into_optional (*_to_pointer ...))

or

  (*_to_pointer ...)

This will allow for inout_to_pointer and array_to_pointer to be pattern matched
robustly and then special cased in SILGenApply.

The reason why these expressions need to be special cased is that they can
perform inout_expr accesses while going through code paths in SILGenApply where
it is expected that inout accesses do not occur.

rdar://29870610
2017-04-10 11:59:33 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Slava Pestov
231cd8ca56 AST: Verify accessor overrides
Make sure that a variable or subscript overrides something iff
the accessors are marked as overrides also. This would have saved
me some debugging time earlier.
2017-03-23 22:20:10 -07:00
practicalswift
83526fe224 [gardening] Use .is<T>() instead of .getAs<T>() if the result is not needed 2017-03-20 22:54:01 +01:00
Erik Eckstein
b4c8b0caa2 Remove the mangling check from ASTVerifier
I’m not sure if this check makes sense with the new mangler.
I removed it because I could not trivially translate this check to the new mangler.
If it turns out that the check makes sense, we can re-add it.
2017-03-17 16:10:36 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Doug Gregor
6668d14d52 Fix wacky indentation. NFC 2017-03-03 10:46:35 -08:00
Doug Gregor
3246b728bd [SR-3917] Allow missing witnesses for optional and unavailable requirements.
This is a bit of a hack to dodge an assertion. In essence, it's a
harmless hack, but we'd like to make the handling of optional and
unavailable requirements more rigorous.
2017-03-02 23:03:10 -08:00
Doug Gregor
348c6b8001 Protocol conformance: store conformances needed for the requirement signature.
The protocol conformance checker verifies that all of the requirements
in the protocol's requirement signature are fulfilled. Save the
conformances from that check into the NormalProtocolConformance,
because this is the record of how that concrete type satisfies the
protocol requirements.

Compute, deserialize, and verify this information, but don't use it
for anything just yet. We'll use this to eliminate the "inherited
protocol map" and possibility some redundant type-witness
information.
2017-03-01 15:32:50 -08:00
Jordan Rose
98ead6bf04 [Verifier] Always check function DeclName / ParamDecl matches. 2017-01-25 13:44:24 -08:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Jordan Rose
22b49d2149 [Verifier] ObjC protocols may have unavailable requirements. (#6862)
...which don't need to have witnesses.

I can't seem to come up with a reduced test case for this one, but it
does fix a verifier failure in the larger project that triggered this.

rdar://problem/29744313
2017-01-17 16:45:02 -08:00
Slava Pestov
5eb16e6b34 Include-what-you-use: Initializer.h should not be pulled in from AST.h 2017-01-09 16:46:31 -08:00
Hugh Bellamy
7a5ef4bdd1 Support building swift/AST with MSVC on Windows 2017-01-09 09:05:06 +00:00
Slava Pestov
7731d4c6cb Sema: Remove some unnecessary calls to getCanonicalType() 2017-01-08 21:01:13 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
2555135bbd AST: Remove DeclContext::isValidGenericContext()
This is intended to have no functional effect, but there was a
minor change to a diagnostic in invalid code in the tests for the
unfinished ASTScope code; I hope I didn't break anything more
fundamental there.
2017-01-04 01:08:28 -08:00
Slava Pestov
fd3101ef7c ASTVerifier: Add missing newline in some printouts 2017-01-04 01:08:28 -08:00
Slava Pestov
d406c4d002 ASTVerifier: Don't check Override attribute if we haven't done early attribute validation
If the 'override' attribute appears on an invalid decl,
it is removed at the start of typeCheckDecl(). However if
the decl is nested inside a multi-statement closure which
is invalid for other reasons, we may have validated it
but not type checked it, in which case we don't want to
crash in the verifier.
2017-01-03 23:40:45 -08:00
Joe Groff
796df2dc44 Merge pull request #6429 from jckarter/type-of-by-overload-resolution
`withoutActuallyEscaping`
2017-01-03 18:47:29 -08:00
Doug Gregor
63498f8fc6 Revert "[AST Verifier] Hack: don't look for destructors of Clang nodes."
This reverts commit bb2fe0dbb2. It was
always a hack, to be replaced with a less-lazy approach to
deserialization.
2017-01-03 09:56:23 -08:00
Joe Groff
0c9297862f Sema: Handle type-checking for withoutActuallyEscaping.
withoutActuallyEscaping has a signature like `<T..., U, V, W> (@nonescaping (T...) throws<U> -> V, (@escaping (T...) throws<U> -> V) -> W) -> W, but our type system for functions unfortunately isn't quite that expressive yet, so we need to special-case it. Set up the necessary type system when resolving an overload set to reference withoutActuallyEscaping, and if a type check succeeds, build a MakeTemporarilyEscapableExpr to represent it in the type-checked AST.
2016-12-22 17:51:26 -08:00
Doug Gregor
bb2fe0dbb2 [AST Verifier] Hack: don't look for destructors of Clang nodes.
The AST verifier is causing late deserialization of generic
environments, which in turn is causing the Clang importer to import
more classes, which don't end up getting proper destructors... causing
an AST verification error. For now, disable this AST verifier check,
because it's causing lots of brokenness rdar://problem/29741827.

A proper fix will take a bit more work.
2016-12-21 13:38:24 -08:00
Slava Pestov
fb0f372e94 AST: Move mapType{In,OutOf}Context() out of ArchetypeBuilder and clean up headers
- The DeclContext versions of these methods have equivalents
  on the DeclContext class; use them instead.

- The GenericEnvironment versions of these methods are now
  static methods on the GenericEnvironment class. Note that
  these are not made redundant by the instance methods on
  GenericEnvironment, since the static methods can also be
  called with a null GenericEnvironment, in which case they
  just assert that the type is fully concrete.

- Remove some unnecessary #includes of ArchetypeBuilder.h
  and GenericEnvironment.h. Now changes to these files
  result in a lot less recompilation.
2016-12-18 19:55:41 -08:00
Slava Pestov
a384b2a677 Don't call VarDecl::getType() on deserialized VarDecls 2016-12-15 22:46:15 -08:00
Jordan Rose
21dfa783b5 Getters for properties with type 'Self' shouldn't use dynamic-self.
That is, a property in a protocol with type 'Self' doesn't promise
that the result type always matches the type of 'self', just the type
of the conforming type. (For a method, a result type of 'Self' /does/
mean you get back a type based on the dynamic 'self', like
Objective-C's 'instancetype'.) This applies even to get-only
properties, and so their accessors should be treated consistently.

With this change, we can have the AST verifier check that getter and
setter types always match up with their property.
2016-12-12 11:33:14 -08:00
Doug Gregor
c250acf8d9 [AST] Record the "owning" declaration context of generic environments.
While not strictly needed for type checking, it's extremely useful for
debugging and verification to know what context a particular generic
environment is associated with. This information was in a kludgy side
table, but it's worth a pointer in GenericEnvironment to always have
it available.
2016-12-07 21:35:53 -08:00