Commit Graph

264 Commits

Author SHA1 Message Date
Xi Ge
ceec130b0a Simplify some code in SourceFile, NFC 2017-09-08 17:19:08 -07:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Slava Pestov
9f8760b942 AST: Remove unused 'resolver' parameter from ModuleDecl::lookupConformance()
... as well as a bunch of downstream plumbing that is no
longer necessary.
2017-09-07 03:36:17 -07:00
Jordan Rose
03e1e3b6e0 Lift nested type lookup fast-pathing up to FileUnit.
We use this to avoid circularity issues in serialization; we'd like to
extend that to the Clang importer. This is only necessary because we
can't look up a single member at a time, but it can still fix issues
in the short term.

This commit should have no effect on functionality.
2017-07-13 17:33:14 -07:00
Slava Pestov
02aed05b6d AST: Remove some dead code 2017-06-16 17:46:00 -07:00
Hugh Bellamy
4dfa6389b0 Introduce and use SWIFT_DELETE_OPERATOR_DELETED 2017-01-16 22:05:27 +00:00
Hugh Bellamy
7a5ef4bdd1 Support building swift/AST with MSVC on Windows 2017-01-09 09:05:06 +00: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
Robert Widmann
cededef0d6 Add condition resolution as a new phrase post-parse
An unfortunately necessary thing to delay defrosting function bodies as
long as we can.
2016-12-14 15:39:19 -05:00
Robert Widmann
72beb9d80d Extract common code into StmtTransformer 2016-12-14 14:59:47 -05:00
Robert Widmann
a060eb5aca [SE-0075] Transfer the power of config resolution to Namebinding
This completely removes Parse’s ability to make any judgement calls
about compilation conditions, instead the parser-relevant parts of
‘evaluateConditionalCompilationExpr’ have been moved into
‘classifyConditionalCompilationExpr’ where they exist to make sure only
decls that we want to parse actually parse later.

The condition-evaluation parts have been moved into NameBinding in the
form of a Walker that evaluates and collapses IfConfigs.  This walker
is meant as an homage to PlaygroundLogger.  It should probably be
factored out into a common walker at some point in the future.
2016-12-14 14:59:47 -05:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
38e58b23aa AST: Fix regression with reference-dependencies-members test
When the call to checkGenericArguments() was removed from
ConformanceChecker::checkConformance(), we stopped recording
a dependency on the extended nominal type when checking an
extension that adds a protocol conformance to the type.

Fix this in a hacky way by recording an explicit dependency
in the same place where we used to call checkGenericArguments().

Surely this is not the best place for it though, so this
should be revisited since I'm pretty sure the old behavior
was an accident.
2016-09-06 11:51:15 -07:00
Doug Gregor
4e214687ca [WIP Name binding] Introduce a basic 'scope map' to model scopes in the AST.
The scope map models all of the name lookup scopes within a source
file. It can be queried by source location to find the innermost scope
that contains that source location. Then, one can follow the parent
pointers in the scope to enumerate the enclosing scopes.

The scope map itself is lazily constructed, only creating scope map
nodes when required implicitly (e.g, when searching for a particular
innermost scope) or forced for debugging purposes.

using a lazily-constructed tree that can be searched by source
location. A search within a particular source location will
2016-09-02 17:13:05 -07:00
David Farler
3c11665d56 [SILGen] Directly silgen access of #dsohandle
Synthesizing a VarDecl for #dsohandle causes some unwanted accessors to
be expected, but we really don't need them: this is a global variable
for the start of the image. There are only two uses of getDSOHandle:
getting the type and emitting the SIL for it. Rather than perform
acrobatics to turn off switches, just emit access directly where it's
needed.

rdar://problem/26565092
2016-07-29 12:09:43 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Doug Gregor
211c580158 [Cleanup] Eliminate DerivedFileUnit.
The only client of DerivedFileUnit was synthesized global '=='
operators for Equatable conformances, which has since been removed.
2016-07-21 12:54:27 -07:00
John McCall
8f44e70b21 Stop passing around these flags as an unsigned. 2016-05-17 15:26:26 -07:00
Doug Gregor
dfc8d5a5f8 [Sema/SILGen] Track per-source-file "used" conformances to reference in SILGen
Sema was dutifully tracking conformances that were "used" as part of
type checking, so it could make sure that those conformances got
completed for SILGen to use. However, this information never actually
made it to SILGen, which included its own (more conservative, not
broad enough) heuristics for finding "used" conformances. Teach Sema
to record conformances within the appropriate source file, and have
SILGen reference the conformances when it emits SIL for the source
file.
2016-05-09 20:43:12 -07:00
Slava Pestov
1ce1e78951 AST: Record -sil-serialize-all in the ModuleDecl
We want to distinguish the special case of a library built with
-sil-serialize-all, from a SIL function that is [fragile] because
of an explicitly @_transparent or @inline(__always).

For now, NFC.
2016-03-28 14:14:49 -07:00
Xi Ge
fda0751cae [SourceKit] In interface-gen request, allow clients to send SourceKit an interested USR from which we can infer the group name. 2016-03-23 17:26:44 -07:00
Xi Ge
3dd149ab99 [SourceKit] CursorInfo: The result of cursor info for a module name starts to include group names in that module. 2016-03-21 17:20:18 -07:00
Doug Gregor
a31edf53d0 Simplify the interface to Module::lookupConformance.
Rather than returning a weird PointerIntPair, return an
Optional<ProtocolConformanceRef>. NFC
2016-03-15 22:08:24 -07:00
Doug Gregor
b051c5a70f Eliminate the unused ConformanceKind::UncheckedConforms. NFC 2016-03-15 22:08:24 -07:00
Xi Ge
c84f667676 [Serialization] Serialize the source order of Decls appearing in their original source file.
We used to think the source order is preserved after de-serialization; however, this seems to be
not the case.
2016-03-08 12:18:10 -08:00
Xi Ge
7a3276738b Re-apply "ModulePrinter: Print decls from the same source file near each other."
This reverts commit 1db83907e3.
2016-03-08 12:18:10 -08:00
Xi Ge
1db83907e3 Revert "ModulePrinter: Print decls from the same source file near each other."
This reverts commit a5c9072344 for mysterious bot test failure.
2016-03-07 23:33:23 -08:00
Xi Ge
a5c9072344 ModulePrinter: Print decls from the same source file near each other. 2016-03-07 22:51:50 -08:00
Xi Ge
9aa3d01101 [Serialization] Avoid serializing source orders, trust deserialized decls in preserving such order. rdar://24610992
Thank Jordan for suggesting this.
2016-02-11 12:24:38 -08:00
Xi Ge
767fba9c92 Rename BriefAndRawComment to CommentInfo. NFC 2016-02-10 19:27:21 -08:00
Xi Ge
98734f588a [Serialization] Serialize and deserialize source order in module doc files. 2016-02-10 17:46:49 -08:00
Xi Ge
329345077b [SourceKit] Add a new query to collect all group names from a module.
Input:
  Request Id: 'source.request.module.groups'
  Required field: 'key.modulename'

Output:
  Array of group names in that module, if any.
2016-02-08 17:22:10 -08:00
Jordan Rose
88ae300e26 Don't forward-declare PointerLikeTypeTraits for Clang types.
It may be an ODR violation, i.e. Clang may already have an instantiation of
the template in its own code.

rdar://problem/24284074
2016-02-06 11:22:28 -08:00
Xi Ge
a25551e54d [SourceKit] Surface group names via cursor info query. 2016-02-05 16:56:41 -08:00
Doug Gregor
9a0241bb3b SE-0022: Address Jordan's review comments about #selector. 2016-01-28 12:09:57 -08:00
Doug Gregor
1a830fa541 SE-0022: Deprecate string-literal-as-selector in favor of #selector.
Introduce Fix-Its to aid migration from selectors spelled as string
literals ("foo:bar:", which is deprecated), as well as from
construction of Selector instances from string literals
(Selector("foo:bar"), which is still acceptable but not recommended),
to the #selector syntax. Jump through some hoops to disambiguate
method references if there are overloads:

    fixits.swift:51:7: warning: use of string literal for Objective-C
         selectors is deprecated; use '#selector' instead
      _ = "overloadedWithInt:" as Selector
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          #selector(Bar.overloaded(_:) as (Bar) -> (Int) -> ())

In the cases where we cannot provide a Fix-It to a #selector
expression, we wrap the string literal in a Selector(...) construction
to suppress the deprecation warning. These are also easily searchable
in the code base.

This also means we're doing more validation of the string literals
that go into Selector, i.e., that they are well-formed selectors and
that we know about some method that is @objc and has that
selector. We'll warn if either is untrue.
2016-01-28 10:58:27 -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
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Chris Lattner
9666f14aa0 change the 'operator new' implementations for Decl and Module to take ASTContext
const qualified, they don't need mutable access.
2015-12-29 21:11:04 -08:00
Ben Langmuir
54f6bb41ff Fix leak of LookupCache
The lookup cache isn't allocated in the ASTContext, so seting up a
destructor cleanup isn't sufficient to get the memory released.  Luckily
SourceFile and BuiltinUnit already have their own destructor called, so
we can use std::unique_ptr.

rdar://problem/22387897

Swift SVN r31561
2015-08-28 21:38:05 +00:00
Chris Willmore
0e326dbeeb Exclude private decls from interface token hash.
After parsing a private decl, reset the token hash state to what it was
before the decl was parsed. This way, adding a private decl or editing
its type or name will not trigger a rebuild of downstream files.

<rdar://problem/22239821> Modifying private APIs shouldn't cause dependents to recompile

Swift SVN r31358
2015-08-20 03:43:43 +00:00
Chris Lattner
8354139213 fix 80 column issue, nfc.
Swift SVN r31103
2015-08-10 06:02:30 +00:00
Jordan Rose
fbb8d3f9a8 Add "interface hash" for improved incremental builds.
Compute the hash of all interface tokens when parsing; write the
interface hash to the swiftdeps file, or if the -dump-interface-hash
option is passed to the frontend. This hash will be used in incremental
mode to determine whether a file's interface has changed, and therefore
whether dependent files need to be rebuilt in response to the change.

Committed on ChrisW's behalf while he gets his setup unborked.

rdar://problem/15352929

Swift SVN r30477
2015-07-22 00:13:54 +00:00
Xi Ge
1ca854d04f Make Decl::isPrivateStdlibDecl() return true if the decl comes from the SwiftShims module.
rdar://20919984

Swift SVN r30230
2015-07-15 22:43:36 +00:00
Slava Pestov
67a1f24d59 Sema: 'dynamic' attribute now diagnoses if Foundation is not imported
This prevents us from seeing a less useful error message from SILGen
further down the line.

Also fix a bug where @objc without importing Foundation was not diagnosed
after the first top-level form. Some tests were relying on this behavior,
so fix those tests, either by splitting off the objc parts of the test, or
just by passing the -disable-objc-attr-requires-foundation-module flag.

Fixes <rdar://problem/20660270>.

Swift SVN r29359
2015-06-10 01:18:27 +00:00
Slava Pestov
b7d448efa6 Revert "Sema: 'dynamic' attribute now diagnoses if Foundation is not imported"
This isn't quite ready.

This reverts commit d63e0f69966eef2fa95841f141d06fb25593cb4b.

Swift SVN r29352
2015-06-08 23:16:16 +00:00
Slava Pestov
637a0884f6 Sema: 'dynamic' attribute now diagnoses if Foundation is not imported
This prevents us from seeing a less useful error message from SILGen
further down the line.

Fixes <rdar://problem/20660270>.

Swift SVN r29351
2015-06-08 22:25:39 +00:00
Jordan Rose
c129637bf6 Name lookup: avoid even calling lookup code on Clang submodules.
This is a hack.

We currently don't put anything in Clang submodules; they're just wrappers
to track what is and isn't visible. All lookups happen through the top-
level module.

This commit adds a new API getImportedModulesForLookup, which is ONLY used
by top-level name lookup and forAllVisibleModules. It is identical to
getImportedModules for everything but ClangModuleUnits, which instead
compute and cache a list of their transitively imported top-level modules.

This speeds up building Foundation.swiftmodule with a release compiler by
a bit more than 5%, and makes a previously lookup-bound test case compile
a third faster than before.

This is a hack.

rdar://problem/20813240

Swift SVN r28598
2015-05-15 01:26:05 +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