Skip to content

Syntax: correct implementation for removing #19972

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 1 commit into from
Oct 30, 2018

Conversation

compnerd
Copy link
Member

llvm::ArrayRef<T> does not define erase. However, since the intent
here is to remove the last n elements, we can use drop_back instead.
Furthermore, replace the direct use of Layout with getLayout().
This was identified by gcc 8.2.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@compnerd
Copy link
Member Author

CC: @bitjammer

@compnerd
Copy link
Member Author

@swift-ci please test

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent here is to remove an element at i.
E.g. given [A, B, C, D], removing(2) returns [A, B, D].

@compnerd
Copy link
Member Author

compnerd commented Oct 22, 2018

@rintaro - bleh, yes, I see your point now that I look at it again. The model that I had in mind was that of an erase from iterator as in the STL. Actually, how is this supposed to work? llvm::ArrayRef is non-owning, so it cannot have a non-contiguous slice. There is no llvm::ArrayRef::erase (and it doesn't make sense in the type).

@rintaro
Copy link
Member

rintaro commented Oct 22, 2018

Yeah, this doesn't work right now. Layout used to be std::vector. But when I changed it to ArrayRef, I forgot to change this method. Thanks for catching this!

I think the easiest way is to make a temporary SmallVector for NewLayout.

@compnerd compnerd force-pushed the removing-syntax branch 2 times, most recently from 8430271 to 1c97ab2 Compare October 23, 2018 17:05
@compnerd
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 018f880108777baf622a9f64b17d9dd41409b280

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 018f880108777baf622a9f64b17d9dd41409b280

@compnerd
Copy link
Member Author

@rintaro - there, this should work I believe. Not sure about the default size, let me know if that needs to be adjusted.

NewLayout.erase(NewLayout.begin() + i);
llvm::SmallVector<RC<RawSyntax>, 16> NewLayout = getRaw()->getLayout();
auto iterator = NewLayout.begin();
std::advance(iterator, i - 1);
Copy link
Member

@rintaro rintaro Oct 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think i - 1 is correct. What if i == 0?
Also, could you add test cases in unittests/Syntax/SyntaxCollectionTests.cpp?

@compnerd
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1c97ab29e1796d67f28bc08d1c16df7f7bead12d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1c97ab29e1796d67f28bc08d1c16df7f7bead12d

@rintaro
Copy link
Member

rintaro commented Oct 29, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3b4919db1cb08b030adf405e0b82334f22d1dd46

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3b4919db1cb08b030adf405e0b82334f22d1dd46

ASSERT_EQ(List.size(), static_cast<size_t>(2));

SmallString<48> Scratch;
llvm::raw_svector_stream OS(Scratch);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-master/swift/unittests/Syntax/SyntaxCollectionTests.cpp:272:27: error: expected ';' after expression
23:37:50   llvm::raw_svector_stream OS(Scratch);
23:37:50                           ^
23:37:50                           ;

I guess:

Suggested change
llvm::raw_svector_stream OS(Scratch);
llvm::raw_svector_ostream OS(Scratch);

`llvm::ArrayRef<T>` does not define `erase`.  However, since the intent
here is to remove the last n elements, we can use `drop_back` instead.
Furthermore, replace the direct use of `Layout` with `getLayout()`.
This was identified by gcc 8.2.
@compnerd
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3b4919db1cb08b030adf405e0b82334f22d1dd46

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3b4919db1cb08b030adf405e0b82334f22d1dd46

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@rintaro rintaro merged commit 8ee83b9 into swiftlang:master Oct 30, 2018
@compnerd compnerd deleted the removing-syntax branch December 11, 2018 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants