Commit Graph

307 Commits

Author SHA1 Message Date
Doug Gregor
28383d4f66 Add back a form of parseIntoSourceFile for LLDB.
This is a temporary shim.
2019-09-03 08:51:37 -07:00
Doug Gregor
d7f6768a9d Eliminate DelayedParsingCallbacks.
DelayedParsingCallbacks only had one implementation, for code
completion, which is only used to determine which bodies to skip and
which to delay. Inline that logic into the parser's delay logic and
remove DelayedParsingCallbacks entirely.
2019-09-02 19:03:07 -07:00
Doug Gregor
d8f7c9e72c [Parser] Introduce a request for parsing type and extension members.
Ensure that lazy parsing of the members of nominal type definitions
and extensions is handled through a request. Most of the effort here
is in establishing a new request zone for parser requests.
2019-08-28 21:39:56 -07:00
Xi Ge
77ba3a21b4 IDE+Evaluator: refactor the implementation of two type checker utilities to evaluator requests. NFC
IDE functionality needs some internal type checking logics, e.g. checking
whether an extension is applicable to a concrete type. We used to directly
expose an header from sema called IDETypeChecking.h so that IDE functionalities
could invoke these APIs. The goal of the commit and following commits is to
expose evaluator requests instead of directly exposing function entry points from
sema so that we could later move IDETypeChecking.h to libIDE and implement these functions
by internally evaluating these requests.
2019-07-22 12:49:36 -07:00
Xi Ge
8915cf8c4d Sourcekit/Evaluator: refactor cursor-info resolver to using the evaluator model. NFC
This change adds a new IDE request ID zone and refactors the cursor-info resolver
to use the request evaluator model.
2019-07-16 09:55:16 -07:00
Jordan Rose
9647483aee Warn when using '@_implementationOnly' inconsistently in a module (#24800)
I thought it would be useful to allow some uses of a module to be
'@_implementationOnly' and others to not be in case someone wanted to
change from one to the other gradually, but it turns out that if
you're trying to /make/ an import implementation-only, you want to
know everywhere you used it.

rdar://problem/50748157
2019-05-16 09:13:34 -07:00
Harlan Haskins
f4da34f363 [ParseableInterface] Only open module buffers once while loading
In addition to being wasteful, this is a correctness issue -- the
compiler should only ever have one view of this file, and it should not
read a potentially different file after validating dependencies.

rdar://48654608
2019-03-21 18:17:07 -07:00
Slava Pestov
fb0fbc099b Parse: Rename DisableDelayedParsing to DelayBodyParsing and change polarity 2019-01-18 00:15:41 -05:00
Xi Ge
6057a60aca [Parser] Expose a flag to allow users explicitly disable delayed parsing. NFC
Discussed with @dcci, this patch is necessary to fix an lldb test failure. rdar://38396444
2019-01-09 14:32:41 -08:00
Argyrios Kyrtzidis
ab7427723e [Parse/Syntax] Refactoring to decouple the parser from syntax tree creation
Instead of creating syntax nodes directly, modify the parser to invoke an abstract interface 'SyntaxParseActions' while it is parsing the source code.
This decouples the act of parsing from the act of forming a syntax tree representation.
'SyntaxTreeCreator' is an implementation of SyntaxParseActions that handles the logic of creating a syntax tree.
To enforce the layering separation of parsing and syntax tree creation, a static library swiftSyntaxParse is introduced to compose the two.

This decoupling is important for introducing a syntax parser library for SwiftSyntax to directly access parsing.
2019-01-07 19:52:59 -08:00
Argyrios Kyrtzidis
66be4a58b4 [Parser] Introduce ParserUnit::parse() function to avoid duplication of code 2018-12-16 09:52:15 -08:00
Argyrios Kyrtzidis
cbad3492e4 [Parse/Syntax] Simplify how the final SourceFileSyntax root is formed
Instead of creating multiple CodeBlockItemList nodes, that need to get merged and discarded later on, do this:

* Ensure for libSyntax parsing that we parse the whole file
* Create top-level CodeBlockItem nodes that we just directly wrap with a single CodeBlockItemList node at the end

The importance of this change will become more obvious later on when we'll decouple syntax parsing from the formation of libSyntax tree nodes.
2018-12-10 13:37:15 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Jordan Rose
a9bbaf751f Assume a SILModule is whole-module when SILGen-ing from a ModuleDecl
No functionality change. Unfortunately we still need the flag in
SILModule itself because of the ability to create an empty SILModule
and parse SIL into it incrementally, which can happen before there's
a FileUnit to use as the associated DeclContext instead of a
CompilerInstance's main module.
2018-09-25 09:13:52 -07:00
Jordan Rose
de07fdfb04 Remove "StartElem" from perform{SIL,IR}Generation
This was only used by the integrated REPL, and is now a dead option.

The "StartElem" option for performTypeChecking is still used for
reading SIL files, which have AST and SIL blocks alternate.
2018-09-25 09:13:52 -07:00
Xi Ge
24b0eac9a4 Parser: parse members in extension decls incrementally. 2018-09-05 17:00:39 -07:00
Doug Gregor
cb7c2b4fce [Name lookup] Introduce requests for several name lookup operations.
Introduce three new requests for name lookup operations that avoid performing
type checking/semantic analysis. They work using syntactic information
(e.g., TypeReprs) and AST-level name lookup operations that will (eventually)
avoid and calls back into type checking. The new requests are:

* Retrieve the superclass declaration of a protocol or class declaration. Use
this request for ClassDecl::getSuperclassDecl() and
ProtocolDecl::getSuperclassDecl().
* Retrieve the types “directly referenced” by a particular location in
an inheritance clause. This query is based on looking at the TypeReprs
and performing fairly-minimal lookup, so it does not involve any Type
computations.
* Retrieve the types “directly referenced” by the underlying type of
a typealias. This query allows us to desugar a typealias without forming
a type.

Along with these is a core operation to transform a set of TypeDecl*s
into a set of NominalTypeDecl*s, looking through typealiases, and
without involving Type at all. The superclass-decl request does this
to find a ClassDecl; other requests will eventually do this to (e.g.)
find all of the protocols mentioned in an inheritance clause.
2018-07-31 10:14:44 -07:00
Slava Pestov
b15c9d7129 Implement a -dump-type-info frontend action 2018-07-30 18:38:47 -07:00
Alex Hoppen
fcc5a6b424 [libSyntax] Enable incremental parsing for syntax tree based syntax coloring 2018-07-17 14:17:58 -07:00
Graydon Hoare
205347321f [AST] Auto-register AST-level requests on ASTContext construction. 2018-07-05 13:00:28 -07:00
Graydon Hoare
465ca073f8 [Sema] Move AccessLevel calculation to AST-level requests. 2018-07-04 16:56:26 -07:00
Doug Gregor
a6f46584ec [Evaluator] Indirect evaluation of uncached requests through a separate table.
The bundling of the form of a request (e.g., the storage that makes up a request)
with the function that evaluates the request value requires us to perform
ad hoc indirection to address the AST —> Sema layering violation. For
example, ClassDecl::getSuperclass() calls through the LazyResolver (when
available) to form the appropriate request. This means that we cannot
use the the request-evaluator’s cache when LazyResolver is null, forcing
all cached state into the AST.

Provide the evaluator with a zone-based registration system, where each
request “zone” (e.g., the type checker’s requests) registers
callbacks to evaluate each kind of request within that zone. The
evaluator indirects through this table of function pointers, allowing
the request classes themselves to be available at a lower level (AST)
than the functions that perform the computation when the value isn’t
in the cache (e.g., Sema).

We are not taking advantage of the indirection yet; that’ll come in a
follow-up commit.
2018-06-29 15:41:55 -07:00
David Ungar
037a2c813b Add cutoff to limit time taking to check exhaustiveness of switch statement. 2018-05-03 10:30:15 -07:00
Vedant Kumar
ca27e829ba Add a transform to help test lldb expression evaluation
The initial version of the debugger testing transform instruments
assignments in a way that allows the debugger to sanity-check its
expression evaluator.

Given an assignment expression of the form:

```
  a = b
```

The transform rewrites the relevant bits of the AST to look like this:

```
  { () -> () in
    a = b
    checkExpect("a", stringForPrintObject(a))
  }()
```

The purpose of the rewrite is to make it easier to exercise the
debugger's expression evaluator in new contexts. This can be automated
by having the debugger set a breakpoint on checkExpect, running `expr
$Varname`, and comparing the result to the expected value generated by
the runtime.

While the initial version of this testing transform only supports
instrumenting assignments, it should be simple to teach it to do more
interesting rewrites.

There's a driver script available in SWIFT_BIN_DIR/lldb-check-expect to
simplfiy the process of launching and testing instrumented programs.

rdar://36032055
2018-03-30 16:50:31 -07:00
omochimetaru
d12542503f [Syntax] test diagnostics in Lexer with libSyntax (#14954) 2018-03-04 08:53:54 +09:00
David Ungar
e7a120f9b3 Avoid copying strings and PrimarySpecificPaths. 2018-02-15 15:34:55 -07:00
David Ungar
fec411e9bc reformatted 2018-02-15 15:34:55 -07:00
David Ungar
1f9a4f3591 Pass around arguments for primary-specific filenames.
Get rid of IRGenOpts attributes that won’t work for batch mode and also remove fakeNamesStub.
2018-02-15 15:34:55 -07:00
Arnold Schwaighofer
2d58f08142 Use clang's effective llvm triple for IR generation
Instead of using the target that was passed to the driver. Use the target from
the clang importer that might have been changed by clang (i.e armv7 to thumbv7
on darwin)

rdar://32599805
2018-02-14 15:45:43 -08:00
Slava Pestov
fc3cf2863a Sema: Infer default witnesses before finishing conformance checking
Otherwise, we'll never get a chance to drain the TypeChecker's
UsedConformances list.

Fixes <https://bugs.swift.org/browse/SR-6565>, <rdar://problem/35949729>.
2017-12-10 20:30:48 -08:00
David Ungar
097dd71ffe Simple fixes per Jordan's comments:
- Use isWholeModuleCompilation in CompilerInstance::createSILModule
- Remove some unneeded timers
- Improve the comment in CompilerInstance::parseAndCheckTypes
- Remove needless const ref to an llvm::function_ref parameter in forEachSourceFileIn
- Remove "OfFile" from "finishTypeCheckingOfFile"
2017-09-21 20:18:34 -07:00
David Ungar
0787be754b Renamed finishTypeChecking to finishTypeCheckingOfSourceFile
To free up that name
2017-09-18 14:01:12 -07:00
Arnold Schwaighofer
034241e440 Revert "Use clang's effective llvm triple for IR generation (#10211)"
This reverts commit 2e3522fafc because debugging
with thumb instructions is broken and being worked on.

rdar://32599805
2017-09-12 13:59:53 -07:00
Harlan
a5098e6b69 Generate libSyntax API (#10926)
* Generate libSyntax API

This patch removes the hand-rolled libSyntax API and replaces it with an
API that's entirely automatically generated. This means the API is
guaranteed to be internally stylistically and functionally consistent.
2017-07-25 18:19:58 -07:00
Jordan Rose
e4794e87f8 [Parse] Simplify SILParserState and its use in Parser.
Preparation for separating ParseSIL out into its own library, but a
nice cleanup regardless.
2017-07-17 12:18:41 -06:00
Harlan
70089a7bcc [Syntax] Represent TokenSyntax as a Syntax node (#10606)
Previously, users of TokenSyntax would always deal with RC<TokenSyntax>
which is a subclass of RawSyntax. Instead, provide TokenSyntax as a
fully-realized Syntax node, that will always exist as a leaf in the
Syntax tree.

This hides the implementation detail of RawSyntax and SyntaxData
completely from clients of libSyntax, and paves the way for future
generation of Syntax nodes.
2017-06-27 11:08:10 -07:00
Mark Lacey
e51e3e4bd4 Update determination of "too complex" expression to take time into account.
By default, end expression type checking after the elapsed process time
is more than 60 seconds for the current expression. This threshold can
be overridden by using -solver-expression-time-threshold=<seconds>.

Resolves rdar://problem/32859654
2017-06-21 16:26:34 -07:00
Roman Levenstein
2a10d8692b Clean-up the code that stored and passes the SILSerializeAll flag around.
- SILSerializeAll flag is now stored in the SILOptions and passed around as part of it
- Explicit SILSerializeAll/wholeModuleSerialized/makeModuleFragile API parameters are removed in many places
2017-06-16 17:50:33 -07:00
Arnold Schwaighofer
2e3522fafc Use clang's effective llvm triple for IR generation (#10211)
* Use clang's effective llvm triple for IR generation

Instead of using the target that was passed to the driver. Use the target from
the clang importer that might have been changed by clang (i.e armv7 to thumbv7
on darwin)

rdar://32599805

* Address review comments

* Fix test case osx-targets.swift

* Fix pic.swift test case

* Fix test abi_v7k.swift

* Address review comment for test osx-targets.swift
2017-06-13 16:26:14 -07:00
Mark Lacey
d26c859222 Add -warn-long-expression-type-checking=<limit> frontend option.
Generates a warning for any expression that takes longer than <limit>
milliseconds to type check. This compliments the existing
-warn-long-function-body=<limit> option.
2017-06-12 17:27:29 -07:00
Graydon Hoare
56460309bc [Stats] Add always-on statistic for NumLLVMBytesOutput. 2017-05-31 17:30:40 -07:00
David Farler
303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -07:00
Xi Ge
daac020c61 Sema: Reject empty switch statements during type checking so that we can issue fixits to fill the unhandled switch cases. (#7766) 2017-02-25 08:01:13 -08:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00
Doug Gregor
579af863c5 Rename ArchetypeBuilder -> GenericSignatureBuilder 2017-02-10 12:46:34 -08:00
Mark Lacey
3903a43f97 Add a command-line option to time expression type-checking. 2017-01-11 00:15:38 -08:00
Robert Widmann
0febbf0b72 Effectively revert #5778
This reverts the contents of #5778 and replaces it with a far simpler
implementation of condition resolution along with canImport.  When
combined with the optimizations in #6279 we get the best of both worlds
with a performance win and a simpler implementation.
2017-01-06 16:16:39 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Maxwell Swadling
a85006dd18 Updated comments based on feedback
Clarified entry points comments. Added formatting detection.
2016-12-19 10:56:41 -08:00
Maxwell Swadling
214efbfc3c Added a new AST Walker that instruments the AST to provide callbacks that simulate a program counter
Based off the PlaygroundTransform, this new ASTWalker leaves calls to __builtin_pc_before and __builtin_pc_after before and after a user would expect a program counter to enter a range of source code.
2016-12-19 10:56:40 -08:00