Commit Graph

166 Commits

Author SHA1 Message Date
Xi Ge
8bde763ba2 IDETypeChecking: make parameter consistently pass reference. NFC 2016-03-03 18:02:13 -08:00
Xi Ge
326514e397 ModulePrinting: when printing synthesized extensions, avoid printing requirements that are known to be true. 2016-03-03 17:42:35 -08:00
Xi Ge
2f41702dd9 IDETypeChecking: Add two utilities canPossiblyConvertTo() and canPossiblyEqual(). 2016-03-02 12:28:02 -08:00
Xi Ge
4e8c8ffe07 IDETypeChecking: Add two utilities to IDETypeChecking.h which are isEqual() and LookUpTypeInContext(). NFC 2016-03-01 15:44:41 -08:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
practicalswift
50f0d0a7bd [gardening] Fix header consistency in recently introduced files 2016-02-05 17:05:35 +01:00
Xi Ge
77b7180f1a Rename CodeCompletionTypeChecking.h to IDETypeChecking.h since it's used by more clients now. NFC 2016-02-04 11:09:21 -08:00
Slava Pestov
81267ce1db AST: Serialize -enable-resilience flag on the ModuleDecl
Since resilience is a property of the module being compiled,
not decls being accessed, we need to record which types are
resilient as part of the module.

Previously we would only ever look at the @_fixed_layout
attribute on a type. If the flag was not specified, Sema
would slap this attribute on every type that gets validated.

This is wasteful for non-resilient builds, because there
all types get the attribute. It was also apparently wrong,
and I don't fully understand when Sema decides to validate
which decls.

It is much cleaner conceptually to just serialize this flag
with the module, and check for its presence if the
attribute was not found on a type.
2016-01-16 02:23:27 -08:00
practicalswift
ca92efc8e6 Use consistent formatting of header comments.
Correct format:
```
//===--- Name of file - Description ----------------------------*- Lang -*-===//
```

Notes:
* Comment line should be exactly 80 chars.
* Padding: Pad with dashes after "Description" to reach 80 chars.
* "Name of file", "Description" and "Lang" are all optional.
* In case of missing "Lang": drop the "-*-" markers.
* In case of missing space: drop one, two or three dashes before "Name of file".
2016-01-04 23:00:53 +01:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
practicalswift
199c4eae2e Consistent use of programming language indicator in top of file comment. 2016-01-04 09:20:19 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Dmitri Gribenko
7778955dc8 Merge pull request #601 from dcci/copycons
[Sema] Provide copy constructor/assignment operator for TypeCheckRequ…
2015-12-19 19:27:08 -08:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
Davide Italiano
be210fcd91 [Sema] Provide copy constructor/assignment operator for TypeCheckRequest.
One of the member variant of the union has a non-trivial copy
constructor, therefore the copy cosntructor is implicitly deleted
(in C++11). Provide the constructor and the copy assignment operator
explictly in order to avoid build errors.
2015-12-16 19:12:34 +00:00
Xi Ge
dd113d0f6c Reapply "[InterfacePrint] When printing a type interface, omit the extensions that are not applicable."
After fixing a dangling pointer.

Swift SVN r32672
2015-10-13 22:08:08 +00:00
Xi Ge
ad3c03243f Revert "[InterfacePrint] When printing a type interface, omit the extensions that are not applicable."
For unhappy bots

Swift SVN r32666
2015-10-13 20:36:06 +00:00
Xi Ge
59c4ca96e8 [InterfacePrint] When printing a type interface, omit the extensions that are not applicable.
Swift SVN r32663
2015-10-13 20:00:03 +00:00
Doug Gregor
278fe4f63b Split the type check request payloads out into a separate .def file. NFC
Swift SVN r32575
2015-10-09 17:27:47 +00:00
Doug Gregor
2d324cac45 Minor cleanups in the iterative type checker. NFC
Only use the existing type checker (via "TC") in the iterative type
checker when we're actually making use of its functionality. The
intent is to drive this usage down to zero as we port code over to the
iterative type checker, so unprincipled uses get in the way.

Swift SVN r32573
2015-10-09 17:18:50 +00:00
Doug Gregor
8c9be9be12 Iterative type checker: simple circular reference detection.
Put in some rudimentary logic for finding circular references within
the iterative type checker and diagnosing those cycles. The
"rudimentary" part is because we're performing linear searches within
a stack rather than keeping a proper dependency graph, which is
inefficient and could display longer cycles than are actually
present. Additionally, the diagnostic is not specialized to the actual
query, so we get a generic "circular reference" diagnostic. OTOH, we
show all of the declarations involved in the cycle, which at least
lets the user figure out where the cycle occurred.

Enable the iterative type checker for resolving the type of a global
typealiases.

Swift SVN r32572
2015-10-09 17:18:49 +00:00
Doug Gregor
c560c377cd Iterative type checker: stub out "structural" type resolution requests.
Introduce a request kind for resolving a TypeRepr, and teach type
resolution the start of performing "structural" resolution of a
TypeRepr that gets the basic structure (e.g., we're pointing at
something that is a nominal type, etc.) without checking its
semantics, dealing with generic arguments, etc.

None of this is active yet.

Swift SVN r32569
2015-10-09 17:18:46 +00:00
Doug Gregor
bbf335e596 Iterative type checker: make request construction more convenient.
Add free functions request##Request(PayloadType), rather than having
to directly construct TypeCheckRequest objects.

Swift SVN r32568
2015-10-09 17:18:45 +00:00
Doug Gregor
d245734773 Iterative type checker: thread an UnsatisfiedDependency through type resolution.
Start threading an (optional) UnsatisfiedDependency callback through type resolution, poke it when we're going to perform name lookup on a particular name.

As part of this, teach type resolution to distinguish between "early return due to unsatisfied dependencies" and "early return due to error", and not to mark type representations as invalid while failing.

This is all inactive code.

Swift SVN r32567
2015-10-09 17:18:44 +00:00
Doug Gregor
bef46010b7 Iterative type checker: add requests for name lookup.
These requests are, thus far, unused.

Swift SVN r32566
2015-10-09 17:18:44 +00:00
Doug Gregor
1ee99dd184 Iterative type checker: make checking dependencies more direct. NFC
Swift SVN r32565
2015-10-09 17:18:43 +00:00
Doug Gregor
b49964e39e Iterative type checker: collapse "enumerate dependencies" and "satisfy".
The separate "enumerate dependencies" and "satisfy" phases didn't make
sense, because one often needs to process part of a request to enumerate
additional dependencies. Collapse these two phases into a single
"process" operation that makes what progress it can, and enumerates
additional dependencies that need to be satisfied before it can
progress further.

Swift SVN r32563
2015-10-09 17:18:41 +00:00
Doug Gregor
f247447f03 Iterative type checker: compute inherited protocols of a protocol.
Introduce a type check request for computing inherited protocols and
start using it in a few places.

Swift SVN r32562
2015-10-09 17:18:40 +00:00
Doug Gregor
72a2969224 Iterative type checker: handle the raw type of an enum
Swift SVN r32560
2015-10-09 17:18:38 +00:00
Doug Gregor
2f71b206e6 Iterative type checker: satisfy dependencies of a request before the request.
Implement some awful, *recursive* code in the *iterative* type checker
that satisfies all of the dependencies of a type check request
(*recursively*) before satisfying the type check request itself. This
is placeholder code that lets us flesh out the dependency mechanism
separately from implementing the proper data structures.

To test this, implement a type check request for type-checking one
type within an inheritance clause. Make the superclass type check
request depend on the first type in the inheritance clause of the
class, with a recovery path that looks at subsequent types in the
inheritance clause so long as we're still seeing protocol types. This
checking is more minimal than what we were doing previously (where we
would check all of the inherited types to find the superclass) and a
simple illustration of dependencies that can evolve.

Swift SVN r32559
2015-10-09 17:18:37 +00:00
Doug Gregor
2feed84c91 Sketch out the interface to an iterative, lazy type checker.
This is all effectively NFC, but lays out the shape of the iterative
type checker: requests are packaged up in TypeCheckRequest, we can
check whether the request has been satisfied already (isSatisfied),
enumerate its dependencies (enumerateDependenciesOf) in terms of other
TypeCheckRequests, and satisfy a request (satisfy).

Lazily-computed semantic information is captured directly in the
AST, but has been set aside in its own structure to allow us to
experiment with moving it into a lookaside table.

The only request that exists now is to type-check the superclass of
the given class. It currently performs unhealthy recursion into the
existing type checker. As we detangle dependencies, this recursion
between the IterativeTypeChecker and the TypeChecker can go away.

Swift SVN r32558
2015-10-09 17:18:36 +00:00
Ben Langmuir
dc910fe53b [CodeCompletion] Handle sequence expression where the LHS type-checks
Now we can handle simple cases like
  1 + 1 == 2 <here>

and correctly suggest both + on the 2 and || on the boolean. When the
LHS doesn't type-check we fallback to using only the operand immediately
to the left.

Swift SVN r32489
2015-10-07 07:30:11 +00:00
Ben Langmuir
9448df6fae [CodeCompletion] Add initial support for completing infix operators
This allows us to start code-completing infix operators in postfix
expressions.  As a first step, this patch only handles completing
against the immediate LHS (so for example 1 == 1 <here> doesn't suggest
boolean operators yet).

The next step is to feed the leading sequence expression from the parser
in so we can consider how the operator being completed fits into the
whole sequence expression.

For rdar://problem/22460167

Swift SVN r32465
2015-10-06 20:48:03 +00:00
Xi Ge
f75ac75d3b [CodeComplete] Try to substitute archetypes with actual types in code completion results.
When completing type members, teach the code completion engine to
transform the archetypes appearing in code completion results to the
actual types. NFC

Swift SVN r31628
2015-09-02 06:22:20 +00:00
Xi Ge
c33e3efe59 [CodeComplete] Complete the right hand side of assignment expressions.
When users complete the right-hand side of an assignment expression, we only
show the results whose types are convertible to those of the left-hand side.

Swift SVN r31357
2015-08-20 01:35:30 +00:00
Xi Ge
0bab23961a [CodeComplete] Refine the code completion results for unresolved members by using constraint solver.
Before this commit, for unresolved members, code completion suggests all visible enum elements
 and option set types. To refine the results, this commit uses constraint solver to infer
the type of unresolved members by analyzing parental expressions. If the solver has solutions,
we complete the unresolved member, otherwise abort.
rdar://16659653

Swift SVN r31195
2015-08-13 00:19:58 +00:00
Chris Lattner
84a6cdcc60 remove an unused method.
Swift SVN r29855
2015-07-01 20:45:48 +00:00
Ben Langmuir
69fdca43da Fix assertion failure code completing after nil literal
We were asserting (and doing the wrong thing) when trying to code
complete
    nil #^HERE^#

The issue is that we tried to apply a solution to the expression that
contained free type variables (converted to generic parameters). This
trips us up when we expect the new type to conform to protocols. In code
completion we generally only need the type of the expression, so this
commit switches to getting that more explicitly.  That said, this did
cause us to drop non-API parameter names in call patterns after an
opening '(' in some cases (covered by rdar://20962472).

Thanks to Doug for suggesting this solution!

rdar://problem/20891867

Swift SVN r28584
2015-05-14 22:22:37 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
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
2015-05-07 21:10:50 +00:00
Doug Gregor
f204351e7e Implement Clang importer support for finding Objective-C methods by selector.
This functionality doesn’t really change what we accept right now, because we eagerly import all of the methods of a class when we do *any* kind of lookup into the class. However, when we manage to stop doing that, this operation will become more important.

Swift SVN r23289
2014-11-12 23:18:42 +00:00
Jordan Rose
2877bd0854 Add support for dependency file generation with -emit-dependencies.
This performs very conservative dependency generation for each compile task
within a full compilation. Any source file, swiftmodule, or Objective-C
header file that is /touched/ gets added to the dependencies list, which
is written out on a per-input basis at the end of compilation.

This does /not/ handle dependencies for the aggregated swiftmodule, swiftdoc,
generated header, or linked binary. This is just the minimum needed to get
Xcode to recognize what needs to be rebuilt when a header or Swift source
file changes. We can revisit this later.

This finishes <rdar://problem/14899639> for now.

Swift SVN r18045
2014-05-14 00:34:11 +00:00
Jordan Rose
0e7bb07b26 Make module loaders owned by the AST context instead of ref-counted.
Also, create the Clang module loader directly rather than indirecting through
a "get constructor" function. It's no longer a valid configuration to not
have a Clang importer.

Swift SVN r16862
2014-04-26 00:57:09 +00:00
Jordan Rose
130ebe4fd4 Revert "Special-case the standard library to always live relative to the compiler."
This reverts r12932; it breaks the iOS simulator build.

Swift SVN r12944
2014-01-24 23:12:24 +00:00
Jordan Rose
4844f22475 Special-case the standard library to always live relative to the compiler.
Import "swift" will now only find "swift.swiftmodule", and only in the
runtime import path.

<rdar://problem/15898866>

Swift SVN r12932
2014-01-24 20:10:26 +00:00
Dmitri Hrybenko
46a4bc1402 Code completion: preserve the AST for the parsed top-level code. This enables
us to find iteration variables while doing code completion in nested top-level
code.

Fixes part of rdar://15199468


Swift SVN r9343
2013-10-15 01:24:16 +00:00
Jordan Rose
25deab5f31 Misc. cleanup related to use of TranslationUnit.
Swift SVN r9164
2013-10-10 19:49:32 +00:00
Jordan Rose
9d3720c8e2 Excise TranslationUnit from some parts of code completion and type checking.
In most cases an ASTContext and/or DeclContext is good enough.

Swift SVN r9013
2013-10-08 00:48:56 +00:00
Jordan Rose
15bfc8db2b Don't type-check imported decls unless referenced in the source file.
Instead, pass a LazyResolver down through name lookup, and type-check
things on demand. Most of the churn here is simply passing that extra
LazyResolver parameter through.

This doesn't actually work yet; the later commits will fix this.

Swift SVN r8643
2013-09-25 20:08:14 +00:00
Jordan Rose
fa3dd42c54 Don't parse function bodies in imported TUs.
...unless the functions are declared [transparent], or if we're in an
immediate mode (in which case we won't get a separate chance to link
against the imported TUs).

This is an optimization that will matter more when we start dealing with
Xcode projects with many cross-file dependencies, especially if we have
some kind of implicit import of the other source files in the project.

In the future, we may want to parse more function bodies for the purpose
of inlining, not just the transparent ones, but we weren't taking
advantage of that now, so it's not a regression. (We're still not taking
advantage of it even for [transparent] functions.)

Swift SVN r7698
2013-08-28 22:53:28 +00:00
Jordan Rose
3e7eef56e7 Kill [stdlib] attribute.
Now that we have true serialized modules, the standard library can import
the Builtin module without any special direction (beyond -parse-stdlib),
and anyone can include those modules without special direction.

Swift SVN r6752
2013-07-30 21:27:42 +00:00