Commit Graph

73 Commits

Author SHA1 Message Date
Rintaro Ishizaki
62c44126b6 [SourceKit] Reuse compiler instance between multiple completion
- Introduce ide::CompletionInstance to manage CompilerInstance
- `CompletionInstance` vends the cached CompilerInstance when:
-- The compiler arguments (i.e. CompilerInvocation) has has not changed
-- The primary file is the same
-- The completion happens inside function bodies in both previous and
   current completion
-- The interface hash of the primary file has not changed
- Otherwise, it vends a fresh CompilerInstance and cache it for the next
  completion

rdar://problem/20787086
2019-12-18 21:52:20 -08:00
Sasha Krassovsky
037f168126 Fix warnings in Parse 2019-09-13 09:57:48 -07:00
Michael Gottesman
7b0d8455ca [ast][silgen] Wire up the case body var decls and use them in SILGenPattern emission to fix the evil fallthrough bug.
rdar://47467128
2019-04-03 23:51:06 -07:00
Michael Gottesman
6af14bdb4b [parse] Implement a dump method on Scope using a new debugVisit method on TreeScopedHashTable.
This is just for use in the debugger when one may want to know what is in the
current scope. The order is not guaranteed but at least it can provide /some/
info ignoring that property. These are no-ops when not in asserts and I put in a
compile time warnign to make sure it is not used in the actual code base.
2019-03-10 15:37:19 -07:00
Rintaro Ishizaki
3794aabffc [Parse] Remove unused ScopeKind 2018-08-29 01:00:02 +09:00
Robert Widmann
d2570cb964 Restore local type declarations list 2017-01-06 16:16:39 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01: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
Hugh Bellamy
732e3c5fdc Fix warnings building swift/Parse on Windows using MSVC 2016-12-07 22:20:49 +00:00
Doug Gregor
f2423b9bbd [Parser] Treat inheritance clauses as a separate scope.
This prevents us from looking in the enclosing scope to resolve names.
2016-12-07 08:10:11 -08:00
Michael Gottesman
59c6a64f5a [gardening] 0 => nullptr. Fixed with clang-tidy. 2016-12-06 23:14:13 -08: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
Doug Gregor
d251c7a731 Merge pull request #1522 from kballard/conditional-compilation-overloads
[Parse] Don't error on overloads in a conditional compilation block
2016-03-14 11:40:04 -07:00
Kevin Ballard
502b159400 [Parse] Store DeclNames in Scope instead of Identifiers
This fixes a problem where compound names like `foo(_:bar:)` were being
resolved to variables declared with the same base name.

Fixes most of SR-880.
2016-03-04 23:42:17 -08:00
Kevin Ballard
a734063bb4 [Parse] Don't error on overloads in a conditional compilation block
Fixes SR-826.
2016-03-03 19:45:00 -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
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Ben Langmuir
6df189b6f4 [CodeCompletion] Restore scope depth in delayed parsing
When the scope depth is wrong and we add a name to the hash table we
will skip the redefinition checks and end up hitting an assertion
failure.

rdar://problem/22344218

Swift SVN r31690
2015-09-04 18:29:45 +00:00
John McCall
a0a16d78d2 Implement the do/catch statement. Tests to follow.
This patch also introduces some SILGen infrastructure for
dividing the function into "ordinary" and "postmatter"
sections, with error-handling-like stuff going into the
final section.  Currently, this is largely undermined by
SILBuilder, but I'm going to fix that in a follow-up.

Swift SVN r26422
2015-03-23 02:08:26 +00:00
Jordan Rose
9b5134d10a [Parse] Don't add local types from inactive #if blocks to the master list.
Otherwise we'll get all the way to IRGen and then try to emit them. And try
to reference them in serialization.

rdar://problem/19935034

Swift SVN r25567
2015-02-26 23:37:20 +00:00
Joe Pamer
988a5877f2 Some updates:
- Respond to Doug's code review feedback
   - Stop hacking around with scopes and use "emplace" to work around RAII in the inactive config case
   - Limit use of StringRef on the front-end, in favor of std::string
   - Use ArrayRef rather than SmallVector within IfConfigDecl
   - Reorder new property declarations on BraceStmt to prevent unnecessary alignment issues
- Update ParseBraceItems to better capture top-level declarations, rather than using token lookahead

Swift SVN r14306
2014-02-24 18:16:49 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00
Joe Groff
9fe1ab427a Implement 'if let' and 'while let' statements.
Allow IfStmts and WhileStmts to have as their condition either an expression, as usual, or a pattern binding introduced by 'var' or 'let', which will conditionally bind to the value inside an optional. Unlike normal pattern bindings, these bindings require an in-line initializer, which will be required to be Optional type. Parse variable bindings in this position, and type-check them by requiring an Optional on the right-hand side and unwrapping it to form the pattern type. Extend SILGen's lowering of if and while statements to handle conditionally binding variables.

Swift SVN r13146
2014-01-30 10:37:39 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Argyrios Kyrtzidis
66d1e516c8 Refactor how multiple parsing passes and delayed parsing works.
-Introduce PersistentParserState to represent state persistent among multiple parsing passes.
  The advantage is that PersistentParserState is independent of a particular Parser or Lexer object.
-Use PersistentParserState to keep information about delayed function body parsing and eliminate parser-specific
  state from the AST (ParserTokenRange).
-Introduce DelayedParsingCallbacks to abstract out of the parser the logic about which functions should be delayed
  or skipped.

Many thanks to Dmitri for his valuable feedback!

Swift SVN r6580
2013-07-25 01:40:16 +00:00
Argyrios Kyrtzidis
de4a2dbd8b [Parser] Abstract a bit access to Parser's ScopeInfo.
This will be more useful later on.

Swift SVN r6578
2013-07-25 01:40:13 +00:00
Dmitri Hrybenko
1c0233efb1 Move lib/Parse/{Parser.h, Scope.h} -> include/swift/Parse/
Swift SVN r6062
2013-07-08 20:36:40 +00:00
Joe Groff
f6d1999569 Parse: Introduce pattern vars into case scopes.
Create a scope for each case block to contain bindings from its patterns, and invoke addVarsToScope after parsing case label patterns to introduce vars into that scope. Refactor addVarsToScope to use an ASTWalker so it finds pattern vars embedded in expr patterns.

Swift SVN r5899
2013-06-29 16:41:57 +00:00
Dmitri Hrybenko
f73d866d91 Implement delayed parsing for function bodies
In order to do this, we need to save and restore parser state easily.  The
important pieces of state are:

* lexer position;
* lexical scope stack.

Lexer position can be saved/restored easily.  We don't need to store the tokens
for the function body because swift does not have a preprocessor and we can
easily re-lex everything we need.  We just store the lexer state for the
beginning and the end of the body.

To save the lexical scope stack, we had to change the underlying data
structure.  Originally, the parser used the ScopedHashTable, which supports
only a stack of scopes.  But we need a *tree* of scopes.  I implemented
TreeScopedHashTable based on ScopedHashTable.  It has an optimization for
pushing/popping scopes in a stack fashion -- these scopes will not be allocated
on the heap.  While ‘detached’ scopes that we want to re-enter later, and all
their parent scopes, are moved to the heap.

In parseIntoTranslationUnit() we do a second pass over the 'structural AST'
that does not contain function bodies to actually parse them from saved token
ranges.


Swift SVN r5886
2013-06-28 22:38:10 +00:00
Dmitri Hrybenko
efffe5c065 Don't add names to non-resolvable scopes
Currently not only we insert names in non-resolvable scopes, but every
overloaded name gets stored only once (the last one wins).  Everything just
happens to work, because we never do name lookup in these scopes.

I also added a ScopeKind to every Scope (instead of just adding the bit --
isResolvableScope), because this provides a better debugging experience, and
centralizes knowledge about what scope kind is resolvable in the function
isResolvableScope(ScopeKind).


Swift SVN r5822
2013-06-26 21:44:11 +00:00
Joe Groff
ac23437886 Replace infix attributes with operator decl lookup
During name binding, associate func decls with operator decls. When parsing SequenceExprs, look up operator decls to determine associativity and precedence of infix operators. Remove the infix_left and infix_left attributes, and make the infix attribute a simple declared attribute [infix] with no precedence.

Operator decls are resolved as follows:

- If an operator is declared in the same module as the use, resolve to the declaration in the current module.
- Otherwise, import operator declarations from all imported modules. If more than one declaration is imported for the operator and they conflict, raise an ambiguity error. If they are equivalent, pick one arbitrarily.

This allows operator declarations within the current module to override imported declarations if desired or to disambiguate conflicting operator declarations.

I've updated the standard library and the tests. stdlib2 and some of the examples still need to be updated.

Swift SVN r4629
2013-04-07 02:43:03 +00:00
Joe Groff
6449655e21 Implement selector-style function definition syntax.
rdar://12315571
Allow a function to be defined with this syntax:

  func doThing(a:Thing) withItem(b:Item) -> Result { ... }

This allows the keyword names in the function type (in this case
`(_:Thing, withItem:Item) -> Result`) to differ from the names bound in the
function body (in this case `(a:Thing, b:Item) -> Result`, which allows
for Cocoa-style `verbingNoun` keyword idioms to be used without requiring
those keywords to also be used as awkward variable names. In addition
to modifying the parser, this patch extends the FuncExpr type by replacing
the former `getParamPatterns` accessor with separate `getArgParamPatterns`
and `getBodyParamPatterns`, which retrieve the argument name patterns and
body parameter binding patterns respectively.



Swift SVN r3098
2012-11-01 21:53:15 +00:00
Eli Friedman
27f8a5ab62 Teach the parser's handling of scopes to handle local types correctly.
Swift SVN r2138
2012-06-04 19:14:58 +00:00
Eli Friedman
ae86d64644 Rename Decl::getLocStart() to Decl::getStartLoc(). Add Decl::getLoc(), which is essentially the location which should be used for diagnostics.
Swift SVN r2105
2012-05-31 23:56:30 +00:00
Eli Friedman
d5e7784010 Get rid of isModuleScope bit, since we don't like scattering bits across the AST; as a replacement, introduce TopLevelCodeDecl, which provides a DeclContext for all expressions and statements at the top level. <rdar://problem/11259941>.
Swift SVN r1503
2012-04-19 21:22:12 +00:00
Eli Friedman
361481835c Introduce a notion of module scope declarations; use it where appropriate instead of checking for a local declcontext.
Swift SVN r1380
2012-04-11 02:52:40 +00:00
Eli Friedman
779a9a331b Err, revert the last patch; apparently scoped hashtables work in mysterious ways.
Swift SVN r1347
2012-04-09 21:51:34 +00:00
Eli Friedman
ce52704f58 Remove unused variable.
Swift SVN r1346
2012-04-09 21:48:55 +00:00
Chris Lattner
cb80e127a6 improve redefinition diagnostics since all type aliases are definitions, not declarations.
Swift SVN r1067
2012-01-18 06:52:15 +00:00
Chris Lattner
ac190abfef completely eliminate the type symbol table. "boom".
Swift SVN r1058
2012-01-17 07:43:32 +00:00
Chris Lattner
2f7cd03c6b switch type lookup to use value lookup for everything. Dead code ahoy.
Swift SVN r1057
2012-01-17 07:36:16 +00:00
Chris Lattner
e51139a3db inline lookupOrInsertTypeNameDecl into its only caller.
Swift SVN r1055
2012-01-17 06:57:17 +00:00
Chris Lattner
d83d5cf1cc "IsUsedAsType" is always true now, nuke it and logic around it.
Swift SVN r1054
2012-01-17 06:54:47 +00:00
Chris Lattner
faa439f28f rip out a bunch of dead logic from the Scope stuff.
Swift SVN r1053
2012-01-17 06:41:37 +00:00
Chris Lattner
627b055989 MetaTypeType doesn't refer to a oneof anymore, it refers to any named type,
which means it wraps a TypeAliasDecl.


Swift SVN r1001
2012-01-11 06:50:24 +00:00
Chris Lattner
7249239ccd Fix some issues where ScopeInfo::addTypeAliasToScope would return
an existing definition (in the redefinition error case) and then
clients didn't check to see if the typealias was already filled in.
They would just clobber an existing typealias.  Solve this by ensuring
that addTypeAliasToScope always returns a new decl.


Swift SVN r1000
2012-01-11 06:36:27 +00:00
John McCall
a1f7eefba3 Extract out decl attributes into a separately-allocated structure.
Swift SVN r920
2011-12-10 00:39:10 +00:00
John McCall
d716f82984 Getterize ValueDecl.
Swift SVN r885
2011-11-18 01:04:12 +00:00