This is an archive of the discontinued LLVM Phabricator instance.

[flang] Sort symbols by creation order
ClosedPublic

Authored by PeteSteinfeld on Mar 8 2021, 5:18 PM.

Details

Summary

We have a "<" operator defined on the type semantics::Symbol that's based on
the symbols' locations in the cooked character stream. This is potentially
problematic when comparing symbols from .mod files when the cooked character
streams themselves might be allocated to varying memory locations.

This change fixes that by using the order in which symbols are created as the
basis for the "<" operator. Thanks to Tim and Peter for consultation on the
necessity of doing this and the idea for what to use as the basis of the sort.

This change in the "<" operator changed the expected results for three of the
tests. I manually inspected the new results, and they look OK to me. The
differences in data05.f90 and typeinfo01.f90 are entirely the order, offsets,
and sizes of the derived type components. The changes in resolve102.f90 are
due to the new, different "<" operator used for sorting.

Diff Detail

Event Timeline

PeteSteinfeld requested review of this revision.Mar 8 2021, 5:18 PM
PeteSteinfeld created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2021, 5:18 PM
PeteSteinfeld added a project: Restricted Project.Mar 8 2021, 5:18 PM
tskeith added inline comments.Mar 9 2021, 6:49 AM
flang/include/flang/Semantics/symbol.h
599–600

There isn't anything specific to maps about this so I think the comment just "collate symbols by creation order".

658

It would make more sense to put nameCount_ in Symbols. And symbolCount_ would be a better name.

Responding to Tim's comments. I moved the data member from "Symbol" to
"Symbols" and renamed it "symbolCount_". Since "Symbols" is a template class,
this meant that I could initialize it directly in the class definition rather
than in the .cpp file.

PeteSteinfeld added inline comments.Mar 9 2021, 9:41 AM
flang/include/flang/Semantics/symbol.h
658

Great suggestions. And for reasons I don't understand, I can initialize static data members directly in the definition of a template class.

tskeith accepted this revision.Mar 9 2021, 10:36 AM
tskeith added inline comments.
flang/include/flang/Semantics/symbol.h
703

This doesn't need to be static.

This revision is now accepted and ready to land.Mar 9 2021, 10:36 AM
This revision was landed with ongoing or failed builds.Mar 9 2021, 12:35 PM
This revision was automatically updated to reflect the committed changes.
PeteSteinfeld added inline comments.Mar 9 2021, 12:36 PM
flang/include/flang/Semantics/symbol.h
703

Thanks, Tim. I'll change this.

klausler added inline comments.Mar 9 2021, 12:48 PM
flang/include/flang/Semantics/symbol.h
703

It need not be static today, since there's just one static instance of this class; but there would be a subtle bug in the future if this member were not static and somebody needed another Symbol allocator instance for inlining or whatever.

PeteSteinfeld added inline comments.Mar 10 2021, 7:01 AM
flang/include/flang/Semantics/symbol.h
703

Good point, Peter. I'll fix this in a follow-in update.