Skip to content

Array Compare Lowering#6597

Merged
dlang-bot merged 4 commits intodlang:masterfrom
somzzz:adCmpT
Mar 8, 2017
Merged

Array Compare Lowering#6597
dlang-bot merged 4 commits intodlang:masterfrom
somzzz:adCmpT

Conversation

@somzzz
Copy link
Contributor

@somzzz somzzz commented Mar 7, 2017

This is the dmd code which calls the new __cmp template from druntime,.
dlang/druntime#1781

semanticTypeInfo(sc, t1.nextOf());

// Lowering to template call
Identifier id = Identifier.idPool("__cmp");
Copy link
Member

Choose a reason for hiding this comment

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

call it __cmp or something like that since that is the id it represents.
Also maybe it would be useful to add it to idgen.d
Such that you don't have to call idPool every time, which is not a cheap call.

@andralex
Copy link
Member

andralex commented Mar 7, 2017

OK, so this should work with the latest update to dlang/druntime#1787, could you please patch that and make sure it works?

@andralex
Copy link
Member

andralex commented Mar 8, 2017

I merged dlang/druntime#1787 so let's see what the autotester says.

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

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

LGTM of course modulo it passing tests. @WalterBright ?

{
semanticTypeInfo(sc, t1.nextOf());

// Lowering to template call
Copy link
Member

@andralex andralex Mar 8, 2017

Choose a reason for hiding this comment

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

Would be nice to document what the template call is (it's not obvious from the sequence of AST node creations and links).

<ihaveadream>
Would be great to have the ability to create an AST fragment from a string source, a la:

auto node = makeExpression!"__cmp($1, $2)"(e1, e2);

whereby makeExpression parses the string during compilation (of dmd), creates the appropriate AST fragment, places the two expressions in lieu of $1 and $2, and returns the created expression node.

I assume a large hunk of compiler code would be drastically simplified.
</ihaveadream>

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, just replace the comment by // Lower to .object.__cmp(e1, e2) or something like that.

if ((t1.ty == Tarray || t1.ty == Tsarray) && (t2.ty == Tarray || t2.ty == Tsarray))
{
semanticTypeInfo(sc, t1.nextOf());

Copy link
Member

Choose a reason for hiding this comment

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

Don't need TypeInfo anymore, so don't need the above line.

arguments.push(e2);

al = new CallExp(loc, al, arguments);
al = al.semantic(sc);
Copy link
Member

Choose a reason for hiding this comment

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

only need one call to semantic() at the end.

al = new CallExp(loc, al, arguments);
al = al.semantic(sc);

al = new CmpExp(op, loc, al, new IntegerExp(loc, 0, Type.tint32));
Copy link
Member

Choose a reason for hiding this comment

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

new IntegerExp(0) is sufficient.

@andralex
Copy link
Member

andralex commented Mar 8, 2017

@somzzz please take a look at the autotester (e.g. https://auto-tester.puremagic.com/show-run.ghtml?projectid=1&runid=2431115&isPull=true), looks like a clerical issue:

Error - file 'ddmd/expression.d' contains trailing whitespace at line 15428

All: I'm also seeing a bazillion of these: ddmd/backend/ptrntab.c:5773: warning: dereferencing type-punned pointer will break strict-aliasing rules.

@somzzz
Copy link
Contributor Author

somzzz commented Mar 8, 2017

@andralex I don't see the trailing whitespace on that line.

Also, it's not clear what the problem with ptrntab.c is since there are no changes in that file.

However it seems like there are issues with dmd tests, I'll look into them. It will probably require fixing __cmp.


al = new CallExp(loc, al, arguments);
al = new CmpExp(op, loc, al, new IntegerExp(0));
al = al.semantic(sc);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I comment this line, test fail_compilation/ice11755.d should pass as the output is the one desired. However, druntime tests will fail.
Calling semantic generates new output which doesn't match the one expected. What is the best approach in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I return al at the end of this code block, I get the following compilation error output for that test:

fail_comp.d(4): Error: floating point operator '!<>=' always returns false for non-floating comparisons
fail_comp.d(5): Error: use '==' for non-floating comparisons rather than floating point operator '!<>'
fail_comp.d(6): Error: use '!=' for non-floating comparisons rather than floating point operator '<>'
fail_comp.d(7): Error: floating point operator '<>=' always returns true for non-floating comparisons
fail_comp.d(8): Error: use '<=' for non-floating comparisons rather than floating point operator '!>'
fail_comp.d(9): Error: use '<' for non-floating comparisons rather than floating point operator '!>='
fail_comp.d(10): Error: use '>=' for non-floating comparisons rather than floating point operator '!<'
fail_comp.d(11): Error: use '>' for non-floating comparisons rather than floating point operator '!<='
fail_comp.d(12): Error: floating point operator '<>=' always returns true for non-floating comparisons
fail_comp.d(13): Error: floating point operator '!<>=' always returns false for non-floating comparisons

There is no more duplication, but the output is not precisely the same as the one expected, which is

fail_compilation/ice11755.d(20): Error: '!<>=' is not defined for array comparisons
fail_compilation/ice11755.d(21): Error: use '==' for non-floating comparisons rather than floating point operator '!<>'
fail_compilation/ice11755.d(22): Error: use '!=' for non-floating comparisons rather than floating point operator '<>'
fail_compilation/ice11755.d(23): Error: '<>=' is not defined for array comparisons
fail_compilation/ice11755.d(24): Error: use '<=' for non-floating comparisons rather than floating point operator '!>'
fail_compilation/ice11755.d(25): Error: use '<' for non-floating comparisons rather than floating point operator '!>='
fail_compilation/ice11755.d(26): Error: use '>=' for non-floating comparisons rather than floating point operator '!<'
fail_compilation/ice11755.d(27): Error: use '>' for non-floating comparisons rather than floating point operator '!<='
fail_compilation/ice11755.d(28): Error: floating point operator '<>=' always returns true for non-floating comparisons
fail_compilation/ice11755.d(29): Error: floating point operator '!<>=' always returns false for non-floating comparisons

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like a specific error message Error: '!<>=' is not defined for array comparisons is replaced with Error: floating point operator '!<>=' always returns false for non-floating comparisons

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling semantic at the very end of the function was the answer to all problems.

@UplinkCoder
Copy link
Member

@somzzz
try https://gist.github.com/UplinkCoder/2a8fd659eef9f3a2fdf8032f700bde80
dmd -run fixwhitespace.d src/ddmd/expression.d

@somzzz
Copy link
Contributor Author

somzzz commented Mar 8, 2017

@UplinkCoder Neat! I checked it out. Luckily there was no whitespace to be found in expression.d.

@andralex
Copy link
Member

andralex commented Mar 8, 2017

Whoa, things are passing. Neat!

@dlang-bot dlang-bot merged commit c87ed3d into dlang:master Mar 8, 2017
@CyberShadow
Copy link
Member

I thought we agreed to check Martin's project tester before merging this to master...

I don't see it in the CI status listing. @MartinNowak ?

@andralex
Copy link
Member

andralex commented Mar 8, 2017

Yah, I was surprised too that setting the auto-merge label didn't wait for the CI to finish.

if (arrayLowering)
{
arrayLowering = arrayLowering.semantic(sc);
return arrayLowering;
Copy link
Member

Choose a reason for hiding this comment

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

Looks a bit pedestrian, nothing wrong with return arrayLowering.semantic(sc);

Copy link
Member

Choose a reason for hiding this comment

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

... in the future :)

Copy link
Contributor

Choose a reason for hiding this comment

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

This style in dmd comes from Walter wanting to be able to trivially insert prints before the return, and I tend to agree.

@JackStouffer
Copy link
Contributor

@andralex The auto-merge label currently doesn't check the project tester. It only looks at the auto-tester, the doc builder, Circle, and CodeCov.

@CyberShadow
Copy link
Member

@MartinNowak What's the status of the project tester, can we see whether this broke anything?

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.

9 participants