Skip to content

Improve the codegen of type symbols for debugging#27613

Merged
jabraham17 merged 44 commits intochapel-lang:mainfrom
jabraham17:improve-codegen-type-symbols
Sep 10, 2025
Merged

Improve the codegen of type symbols for debugging#27613
jabraham17 merged 44 commits intochapel-lang:mainfrom
jabraham17:improve-codegen-type-symbols

Conversation

@jabraham17
Copy link
Member

@jabraham17 jabraham17 commented Aug 7, 2025

Improves the codegen of chapel type symbols, especially for debugging.

Key Improvements

  • Adds special debug types for bools and enums
  • Heavily refactors llvmDebug.cpp to make way for future improvements
  • makes codegen of enums for LLVM and C use the same logic
    • this means the C backend no longer relies on the behavior of C enums, a value is always given

This PR also makes a few improvements to sub_test

Makes progress on #27603

  • paratest with/without gasnet

Future work

  • get the original array motivating case working (resolving the TODO added in this PR about forward decls)
  • improve the pretty printers to work with the fixed llvm types
  • make the compile unit for types be correct, right now they get put in whatever compile unit is codegened first
  • figure out whats going on with the garbage values in this test case. lldb seems to think x and y are garbage, but only if R has no other fields and an explicit init
    class A {
      var x: int;
      var y: real;
    }
    
    record R {
      var a: unmanaged A;
      proc init() {
        this.a = new unmanaged A();
      }
    }
    
    proc main() {
      var cc = new R();
      writeln("cc: ", cc);
      use Debugger; breakpoint;
    }
    

[Reviewed by @DanilaFe ]

@jabraham17 jabraham17 force-pushed the improve-codegen-type-symbols branch from 1d58dcc to 1355edb Compare August 8, 2025 15:03
@jabraham17 jabraham17 force-pushed the improve-codegen-type-symbols branch from 9754603 to c62b401 Compare September 4, 2025 01:05
…h of other type cleanups

Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
…ugging

Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
@jabraham17 jabraham17 force-pushed the improve-codegen-type-symbols branch from c62b401 to 7524ca8 Compare September 4, 2025 23:08
@jabraham17 jabraham17 marked this pull request as ready for review September 4, 2025 23:09
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Copy link
Contributor

@DanilaFe DanilaFe left a comment

Choose a reason for hiding this comment

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

Looks good, though I didn't study the details of the seds in the test files, or sanity-check the dwarfdump output.

if (constant->init) {
fprintf(outfile, " = %s", constant->init->codegen().c.c_str());
}
fprintf(outfile, "%s = %s", sym->codegen().c.c_str(), var->codegen().c.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

Double-checking: this changes our generated C code, but you're saying it's acceptable because, even supposing an enum like:

// (Chapel)
enum { a, b = 12, c, d = 5 }

Other transformations convert the above into:

// (Chapel)
enum { a, b = 12, c = 13, d = 5 }

Which was equivalent to the generated C code:

// C++
enum { a, b = 12, c = 13, d = 5 }

Here, C will start number at zero by default, so the new form

enum { a = 0, b = 12, c = 13, d = 5 }

Retains the original behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Put another way: I took the logic we had for generating enums with LLVM (which emulates what the C backend does) and used it for both LLVM and C

Copy link
Member Author

Choose a reason for hiding this comment

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

And if it helps, we have tests like test/types/enum/enumCast.chpl which lock in the integer value based on C semantics, and they still pass with this change

INT_FATAL("Unable to find LLVM type for field %s of type %s in struct %s",
field->cname, fts->cname, type->symbol->name);
}
return nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the FIXME?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because now I have added the INT_FATAL if they are missing. Its an internal error instead of just a comment in the code. Which means if a user hits this in the field (unlikely, if both fts->getLLVMType(); and getTypeLLVM(fts->cname) fail, there are probably other issues beyond debug info), they get an internal error and report it, and we fix it

Copy link
Member Author

Choose a reason for hiding this comment

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

And while debugging, I have yet to actually hit this branch

Comment on lines -412 to -425
myTypeDescriptors[type] = N;
return llvm::cast_or_null<llvm::DIType>(N);
}
else if(this_class->aggregateTag == AGGREGATE_CLASS) {
N = dibuilder->createStructType(
get_module_scope(defModule),
name,
get_file(defModule, defFile),
defLine,
layout.getTypeSizeInBits(ty),
8*layout.getABITypeAlign(ty).value(),
llvm::DINode::FlagZero,
derivedFrom,
dibuilder->getOrCreateArray(EltTys));
Copy link
Contributor

Choose a reason for hiding this comment

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

are my eyes playing tricks on me, or was this all the same code?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was pretty much all the same code. There are some very very subtle differences that I preserved as best I can. Basically the differences stemmed from "pointer to class" vs "class"

Comment on lines +2 to +3
CHPL_COMM!=none
COMPOPTS <= --no-local
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not skipif these instead of suppressing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because ideally, one day they work. These are copied from the existing targetVar.suppressif

Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
@jabraham17 jabraham17 merged commit e644057 into chapel-lang:main Sep 10, 2025
10 checks passed
@jabraham17 jabraham17 deleted the improve-codegen-type-symbols branch September 10, 2025 00:17
@bradcray
Copy link
Member

With a quick glance at the OP, this feels more like a feature freeze item than a code freeze item…?

@jabraham17
Copy link
Member Author

This was discussed last week in the release round table as a code freeze item. Perhaps it wasn't fully clear the extent of the changes

jabraham17 added a commit that referenced this pull request Sep 10, 2025
Fixes a few errors from merging
#27613

- fixes merge issues between
#27613 and
#27777 in the pretty printer
- adds missing skipifs and suppressifs where needed
- while there, removes an unrelated .bad file which is causing other
nightly failures
- fixes the typed pointers build with LLVM 14

[Reviewed by @lydia-duncan]
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