8000 Cherry-pick some post-4.2 changes into swift-4.2-branch by allevato · Pull Request #6 · swiftlang/swift-syntax · GitHub
[go: up one dir, main page]

Skip to content

Cherry-pick some post-4.2 changes into swift-4.2-branch #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d259fcc
Simplify AbsolutePosition offset calculation and support columns
Apr 10, 2018
5018466
Clarify comment
Apr 24, 2018
8044478
Un-rename property
Apr 24, 2018
b664867
Monomorphize AbsolutePosition.copy()
Apr 24, 2018
23502d3
Rename byteOffset to utf8Offset and remove utf16
Apr 24, 2018
b970c42
Re-add AbsolutePosition.swift
Apr 24, 2018
cc54246
Actually add offsets in add(columns:) and add(lines:size:)
Apr 24, 2018
60e37d0
Add accessors for source locations and test diagnostic emission (#16141)
harlanhaskins Apr 26, 2018
3dc6e42
Manually cherry-pick tests from apple/swift:
allevato Aug 31, 2018
a2ed7fb
Add descriptions for SwiftSyntax errors (#16339)
harlanhaskins May 3, 2018
54ea839
SwiftSyntax: Allow absolute position access for dangling nodes.
nkcsgexi May 3, 2018
08fb8a0
Add incremental syntax tree deserialization to SwiftSyntax
ahoppen May 24, 2018
7deb6b4
Make RawSyntax a struct
ahoppen May 24, 2018
f104c5f
Add type annotations to speed up compile time
ahoppen Jun 26, 2018
156cc9f
Don't throw just because compilation fails
ahoppen Jul 26, 2018
9bf9210
Record the nodes that have been reused during an incremental transfer
ahoppen May 30, 2018
6294ff3
Refactor AbsolutePosition
ahoppen Jun 28, 2018
84c6d0d
Make AbsolutePosition a value type
ahoppen Aug 14, 2018
b7deaa6
Remove validate methods
ahoppen Aug 23, 2018
9cef71e
Make SourceLength a struct
ahoppen Aug 29, 2018
2703c00
Make RawSyntaxData a direct enum
ahoppen Aug 29, 2018
f511ccc
Don't set the process terminationHandler in SwiftcInvocation
ahoppen Aug 29, 2018
e58d288
Update tests after cherrypicks.
allevato Sep 7, 2018
5d9650b
Allow *ListSyntax nodes to be visited.
allevato Sep 7, 2018
bd3484b
Apply review fixes
allevato Sep 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make SourceLength a struct
  • Loading branch information
ahoppen authored and allevato committed Sep 7, 2018
commit 9cef71e7b79246238cf002985e58609c8032d161
19 changes: 14 additions & 5 deletions Sources/SwiftSyntax/RawSyntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ extension CodingUserInfoKey {
CodingUserInfoKey(rawValue: "SwiftSyntax.RawSyntax.OmittedNodeLookup")!
}

/// Box a value type into a reference type
class Box<T> {
let value: T

init(_ value: T) {
self.value = value
}
}

/// A ID that uniquely identifies a syntax node and stays stable across multiple
/// incremental parses
public struct SyntaxNodeId: Hashable, Codable {
Expand Down Expand Up @@ -72,11 +81,11 @@ struct RawSyntax: Codable {
/// incremental parses
let id: SyntaxNodeId

var _contentLength = AtomicCache<SourceLength>()
var _contentLength = AtomicCache<Box<SourceLength>>()

/// The length of this node excluding its leading and trailing trivia
var contentLength: SourceLength {
return _contentLength.value() {
return _contentLength.value({
switch data {
case .node(kind: _, layout: let layout):
let firstElementIndex = layout.firstIndex(where: { $0 != nil })
Expand All @@ -97,11 +106,11 @@ struct RawSyntax: Codable {
contentLength += element.trailingTriviaLength
}
}
return contentLength
return Box(contentLength)
case .token(kind: let kind, leadingTrivia: _, trailingTrivia: _):
return SourceLength(of: kind.text)
return Box(SourceLength(of: kind.text))
}
}
}).value
}

init(kind: SyntaxKind, layout: [RawSyntax?], presence: SourcePresence,
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/SourceLength.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// The length a syntax node spans in the source code. From any AbsolutePosition
/// you reach a node's end location by either adding its UTF-8 length or by
/// inserting `lines` newlines and then moving `columns` columns to the right.
public final class SourceLength {
public struct SourceLength {
public let newlines: Int
public let columnsAtLastLine: Int
public let utf8Length: Int
Expand Down Expand Up @@ -90,4 +90,4 @@ extension AbsolutePosition {
public static func +=(lhs: inout AbsolutePosition, rhs: SourceLength) {
lhs = lhs + rhs
}
}
}
9 changes: 0 additions & 9 deletions Sources/SwiftSyntax/SyntaxData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ import Foundation
/// exposed to clients.
typealias NodeIdentifier = [Int]

/// Box a value type into a reference type
fileprivate class Box<T> {
let value: T

init(_ value: T) {
self.value = value
}
}

/// SyntaxData is the underlying storage for each Syntax node.
/// It's modelled as an array that stores and caches a SyntaxData for each raw
/// syntax node in its layout. It is up to the specific Syntax nodes to maintain
Expand Down
0