Skip to content
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

Tsify lib/compilers #4609

Merged
merged 17 commits into from
Jan 29, 2023
Merged

Tsify lib/compilers #4609

merged 17 commits into from
Jan 29, 2023

Conversation

jeremy-rifkin
Copy link
Member

No description provided.

@jeremy-rifkin jeremy-rifkin marked this pull request as ready for review January 17, 2023 06:18
execute: false,
demangle: false,
libraryCode: false,
trim: false,
Copy link
Member Author

Choose a reason for hiding this comment

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

Are these the right defaults?

Copy link
Member

Choose a reason for hiding this comment

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

I think we need: demangle: true but everything else looks good to me. @partouf is that the right default for libraryCode - I think so.

Copy link
Contributor

@partouf partouf Jan 27, 2023

Choose a reason for hiding this comment

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

both demangle and libraryCode and are defaulted to true in the UI, but so are directives and commentOnly, I think we leave the defaults to the UI and people using the API should do everything manually. Because then they'll know what might be filtered out - instead of having everything filtered out by default and then they don't know what they might be missing.

Copy link
Member

Choose a reason for hiding this comment

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

I don't really know what this is doing, but it's probably missing binaryObject if the goal is to init all possible filters.

Copy link
Contributor

Choose a reason for hiding this comment

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

please, do add 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.

BaseCompiler.getDefaultFilters is implemented as

getDefaultFilters() {
return {
binary: false,
execute: false,
demangle: true,
intel: true,
commentOnly: true,
directives: true,
labels: true,
optOutput: false,
libraryCode: false,
trim: false,
};
}

It looks like the return type should be ParseFiltersAndOutputOptions so I will update 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.

@dkm What should the default for binaryObject be?

Copy link
Member

Choose a reason for hiding this comment

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

I am pretty sure false. I think we could "just" try that and fix it up (in order to get this merged)

{
text: objResult.stdout,
},
],
Copy link
Member Author

Choose a reason for hiding this comment

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

Unsure if this is correct, just made a best guess for how to put this in a ParsedAsmResult

Copy link
Member

Choose a reason for hiding this comment

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

Very good question .. this will need to be tested. But...I wonder how it worked before if this isn't quite right ...

Copy link
Member

Choose a reason for hiding this comment

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

I'm cool with finding out by merging and dealing with the consequences

Copy link
Member

Choose a reason for hiding this comment

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

With the regression in #4668 I'm wondering how this worked before 🤔

{
text: `<No output: javap returned ${objResult.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.

Same here

const maxSize = this.env.ceProps('max-asm-size', 64 * 1024 * 1024);
const optPromise = result.hasOptOutput ? this.processOptOutput(result.optPath) : Promise.resolve('');
const asmPromise = (
filters.binary
? this.objdump(outputFilename, {}, maxSize, filters.intel, filters.demangle, filters)
? this.objdump(outputFilename, {}, maxSize, filters.intel, filters.demangle, false, false, filters)
Copy link
Member Author

Choose a reason for hiding this comment

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

Typescript uncovered a bug here, staticReloc and dynamicReloc weren't being passed. Is passing false for both appropriate?

Copy link
Member

Choose a reason for hiding this comment

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

I think so: @dkm I think is the one to know for certain.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, passing false is valid in case of doubt. Using true will add extra parameters to objdumper, which may or may not be a good idea (don't know anything about nvcc tools)

const dirPath = path.dirname(outputFilename);
const execBinary = this.getExecutableFilename(dirPath);
if (await utils.fileExists(execBinary)) {
return super.objdump(execBinary, result, maxSize, intelAsm, demangle);
return super.objdump(execBinary, result, maxSize, intelAsm, demangle, staticReloc, dynamicReloc, filters);
Copy link
Member Author

Choose a reason for hiding this comment

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

Same here, three arguments weren't being passed and also weren't present in the parameter list. I went ahead and just added them to the parameters / forwarded.

return exec.execute(python, python_args, options);
}
logger.error(`Invalid ppci path ${compiler}`);
assert(false, `Invalid ppci path ${compiler}`);
Copy link
Member Author

Choose a reason for hiding this comment

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

I think an assert here is appropriate. Something to kill the code path is needed otherwise TS isn't happy that undefined is being returned.

Copy link
Member

Choose a reason for hiding this comment

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

How is assert(false) better than throw new Error() in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that'd be more or less equivalent. assert does ultimately throw a new Error internally. So it's just whatever extra diagnostics assert adds in.

Copy link
Member

Choose a reason for hiding this comment

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

Got it. Maybe we should make a fatalError(); that makes it clear? (I just have a vague dislike of assert(false) but that's mainly C PTSD..:)

const match = line.replace(/\x1B\[[\d;]*[Km]/g, '').match(re);
if (match) {
lineObj.text = `<source>:${match[1]} ${match[2].trim()}`;
lineObj.tag = {
severity: 0,
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if this is correct, some severity is needed for the tag

text: 'Failed to run compiler to get MLIR 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.

Not sure if this is correct, made a best effort to get things into the correct form

Copy link
Member

Choose a reason for hiding this comment

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

100%

lib/compilers/win32.ts Show resolved Hide resolved
@@ -37,7 +37,7 @@ export type ParsedAsmResult = {
parsingTime?: string;
filteredCount?: number;
externalParserUsed?: boolean;
objdumpTime?: number;
objdumpTime?: number | string;
Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently it's set to a string in one of the compilers

Copy link
Member

Choose a reason for hiding this comment

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

Oh that's odd - which compiler? Seems like it ought not to be (maybe a TODO?)

Copy link
Member Author

Choose a reason for hiding this comment

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

java was the only compiler erroring however other compilers do similar assignments, e.g. clang does result.objdumpTime = objResult.execTime; but result is any (objResult.execTime is a string). I'm not sure how this type is used throughout the codebase, I'll go ahead and add a TODO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Its set to a string, but the frontend always takes that into account. There was a good reason for it, but I really can’t remember why. But it is what it is. We can change it later on when we have a clear view of what everything is and should be

@jeremy-rifkin
Copy link
Member Author

Ok, not sure what is causing that test to fail. Will investigate more tomorrow.

@jeremy-rifkin
Copy link
Member Author

Ah shoot lots of merge conflicts because I did npm run lint on main, should have waited

Copy link
Member

@mattgodbolt mattgodbolt left a comment

Choose a reason for hiding this comment

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

ran out of time at 32/78 files reviewd. looking good though!

@@ -98,7 +98,7 @@ export class BaseCompiler implements ICompiler {
protected toolchainPath: any;
public possibleArguments: CompilerArguments;
protected possibleTools: ITool[];
protected demanglerClass: any;
protected demanglerClass: any; // TODO(jeremy-rifkin): Will be able to do better once #4607 lands
Copy link
Member

Choose a reason for hiding this comment

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

#4607 has landed now (yay)

@@ -1254,7 +1254,7 @@ export class BaseCompiler implements ICompiler {
}
}

getExecutableFilename(dirPath, outputFilebase, key?) {
getExecutableFilename(dirPath: string, outputFilebase: string, key?) {
Copy link
Member

Choose a reason for hiding this comment

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

do we know what the key? type is? looks like : any from getOutputFilename though I suspect it's possible to imrpove on that...though not in this PR necessarily

Copy link
Contributor

Choose a reason for hiding this comment

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

I think key "should" be something that looks like the result of https://github.com/compiler-explorer/compiler-explorer/blob/main/lib/base-compiler.ts#L1681 and in some cases what's returned by https://github.com/compiler-explorer/compiler-explorer/blob/main/lib/base-compiler.ts#L1685 - in theory at least

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll probably defer this to another PR, this PR is a big enough review already :)

Copy link
Member

Choose a reason for hiding this comment

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

100%

execute: false,
demangle: false,
libraryCode: false,
trim: false,
Copy link
Member

Choose a reason for hiding this comment

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

I think we need: demangle: true but everything else looks good to me. @partouf is that the right default for libraryCode - I think so.

@@ -49,8 +50,8 @@ export class JaktCompiler extends BaseCompiler {
maxSize: number,
intelAsm,
Copy link
Member

Choose a reason for hiding this comment

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

aren't these also boolean too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, this matches the definition in BaseCompiler at the moment

Copy link
Member

Choose a reason for hiding this comment

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

got it :)

{
text: objResult.stdout,
},
],
Copy link
Member

Choose a reason for hiding this comment

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

Very good question .. this will need to be tested. But...I wonder how it worked before if this isn't quite right ...

@partouf
Copy link
Contributor

partouf commented Jan 27, 2023

I'm really not happy about all the constructors getting passed the type CompilerInfo & Record<string, any> - if we can't yet solidify the CompilerInfo type, then at least make a separate type CompilerInfo = IncompleteCompilerInfo & Record<string, any> or something so that we don't have to go back and change all the constructors again and have just 1 spot to change it.

@github-actions github-actions bot added the ui label Jan 28, 2023
@jeremy-rifkin
Copy link
Member Author

@partouf You're absolutely right, I'm not sure why I did that 😄 I went ahead and fixed the CompilerInfo type

@mattgodbolt
Copy link
Member

I realised I just did a couple of these in separate PRs; whoops. Will review this instead 👍

Copy link
Member

@mattgodbolt mattgodbolt left a comment

Choose a reason for hiding this comment

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

LGTM! I think we should fail forward. I'm a bit confused about the TODOs that refer their own PR number...are those planned to be done before merging? If so: great, if not then they will refer to a closed issue :)

@@ -99,7 +99,8 @@ export class BaseCompiler implements ICompiler {
protected toolchainPath: any;
public possibleArguments: CompilerArguments;
protected possibleTools: ITool[];
protected demanglerClass: any;
// TODO(jeremy-rifkin): Will be able to do better once #4607 lands
Copy link
Member

Choose a reason for hiding this comment

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

#4607 has landed (but the TODO stands)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah shoot I wasn't paying attention here, ty!

@@ -1254,7 +1254,7 @@ export class BaseCompiler implements ICompiler {
}
}

getExecutableFilename(dirPath, outputFilebase, key?) {
getExecutableFilename(dirPath: string, outputFilebase: string, key?) {
Copy link
Member

Choose a reason for hiding this comment

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

100%

@@ -2225,7 +2231,9 @@ export class BaseCompiler implements ICompiler {

if (!bypassCache) {
const cacheRetreiveTimeStart = process.hrtime.bigint();
const result = await this.env.cacheGet(key);
// TODO: Because key coantains a CompilerInfo which contains a function member it can't be assigned to a
Copy link
Member

Choose a reason for hiding this comment

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

what is the "todo" part? This seems like a reason to cast to any for sure, but I'm not sure what the action to take is.

Copy link
Member Author

Choose a reason for hiding this comment

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

TODO to eliminate the ugly any cast, key should be cacheable (if it's not that's a big problem), it's just a matter of getting the types lined up

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll update it to be more clear

execute: false,
demangle: false,
libraryCode: false,
trim: false,
Copy link
Member

Choose a reason for hiding this comment

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

I am pretty sure false. I think we could "just" try that and fix it up (in order to get this merged)

@@ -49,8 +50,8 @@ export class JaktCompiler extends BaseCompiler {
maxSize: number,
intelAsm,
Copy link
Member

Choose a reason for hiding this comment

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

got it :)

{
text: objResult.stdout,
},
],
Copy link
Member

Choose a reason for hiding this comment

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

I'm cool with finding out by merging and dealing with the consequences

// These options make LDC produce an AST dump in a separate file `<inputFilename>.cg`.
const newOptions = options.concat('-vcg-ast');
const execOptions = this.getDefaultExecOptions();
// TODO(#4609) generateAST expects to return a ResultLine[] not a string
Copy link
Member

Choose a reason for hiding this comment

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

This TODO refers to itself? Should be a separate issue unless you plan o nfixing it before merging?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to do the same thing we did in #4490, I can make a separate issue for this though

return exec.execute(python, python_args, options);
}
logger.error(`Invalid ppci path ${compiler}`);
assert(false, `Invalid ppci path ${compiler}`);
Copy link
Member

Choose a reason for hiding this comment

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

How is assert(false) better than throw new Error() in this case?

text: 'Failed to run compiler to get MLIR code',
},
],
};
Copy link
Member

Choose a reason for hiding this comment

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

100%

@@ -37,7 +37,8 @@ export type ParsedAsmResult = {
parsingTime?: string;
filteredCount?: number;
externalParserUsed?: boolean;
objdumpTime?: number;
// TODO(#4609) A few compilers seem to assign strings here. It might be ok but we should look into it more.
Copy link
Member

Choose a reason for hiding this comment

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

Another self-referencing TODO?

@jeremy-rifkin jeremy-rifkin merged commit 6a6efae into main Jan 29, 2023
@jeremy-rifkin jeremy-rifkin deleted the jr/tsify/compilers branch January 29, 2023 18:22
@mattgodbolt
Copy link
Member

woo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants