Skip to content

Move addDefaultVersionIdentifiers from mars.d to compiler.d#7524

Closed
RazvanN7 wants to merge 1 commit intodlang:masterfrom
RazvanN7:Mars_refactor
Closed

Move addDefaultVersionIdentifiers from mars.d to compiler.d#7524
RazvanN7 wants to merge 1 commit intodlang:masterfrom
RazvanN7:Mars_refactor

Conversation

@RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Dec 26, 2017

The frontend interface of the compiler library needs to do some initialization which is done in dmd/mars.d. In order to use initialization methods from mars.d there are 3 options:

  1. Duplicate the code in frontend.d
  2. Import mars.d and use the method.
  3. Put it in another file and make frontend.d and mars.d use it

(1), (2) are obviously bad solutions, so this PR implements (3)

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.


VersionCondition.addPredefinedGlobalIdent("D_HardFloat");

printPredefinedVersions();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm we should we really do this by default in this method?
How about moving printPredefinedVersions back to mars.d?

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's ok to let it there since the printPredefined versions has all it's code in a block nested by a if (global.params.verbose)

Copy link
Member

Choose a reason for hiding this comment

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

printPredefinedVersions() has nothing to do with addDefaultVersionIdentifiers() - note that no mention of it is made in the Ddoc comment - it should not be called here.

else
static assert(0, "OS not supported yet.");

addDefaultVersionIdentifiers();
Copy link
Contributor

Choose a reason for hiding this comment

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

You can now remove the OS detection above :)
I had to make a copy of this as addDefaultVersionIdentifiers was private and I wanted to keep the changes to a minimum in the initial version.

* Note that if `-defaultlib=` or `-debuglib=` was used,
* we don't override that either.
*/
void setDefaultLibrary()
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure whether this can be re-used by other compilers or the frontend. It looks fairly specific to DMD.

@jacob-carlborg
Copy link
Contributor

Note that there's this PR as well #7485.

@RazvanN7 RazvanN7 force-pushed the Mars_refactor branch 3 times, most recently from d2dcbf6 to 52b32f5 Compare December 28, 2017 10:43
@RazvanN7 RazvanN7 changed the title Refactor init methods out from mars.d Move addDefaultVersionIdentifiers from mars.d to compiler.d Dec 28, 2017
@RazvanN7 RazvanN7 force-pushed the Mars_refactor branch 2 times, most recently from ab00dd9 to 26d0f14 Compare December 28, 2017 10:50
@wilzbach
Copy link
Contributor

wilzbach commented Jan 3, 2018

@RazvanN7 this needs another rebase

else
static assert(0, "OS not supported yet.");

addDefaultVersionIdentifiers();
Copy link
Member

Choose a reason for hiding this comment

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

printPredefinedVersions() call should go here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

else version(OpenBSD)
global.params.isOpenBSD = 1;
else
static assert(0, "OS not supported yet.");
Copy link
Member

Choose a reason for hiding this comment

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

I see all this is deleted, but I don't see where it is moved to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that addDefaultVersionIdentifiers is called there is no need to do that since the code was duplicated from it initially.

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Jan 5, 2018

@wilzbach I addressed the issues. I think we're good to go. I had to add -J../res to the parser and lexer library builds otherwise the tests would fail

@RazvanN7 RazvanN7 force-pushed the Mars_refactor branch 3 times, most recently from fd14a30 to eb4ad41 Compare January 5, 2018 11:00
@jacob-carlborg
Copy link
Contributor

I had to add -J../res to the parser and lexer library builds otherwise the tests would fail

Hmm, that's strange. The only file in the res directory is default_ddoc_theme.ddoc which is only used in dmd.doc.

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Jan 5, 2018

Furthermore, globals.d imports compiler.d which for the sake of addDefaultVersionIdentifiers imports cond.d which is a gateway to other non parser related files. I guess compiler.d should not be part of the parser.

@ibuclaw
Copy link
Member

ibuclaw commented Jan 5, 2018

I'll remove the import of dmd.compiler from the globals module tomorrow.

@ibuclaw
Copy link
Member

ibuclaw commented Jan 6, 2018

Shouldn't this be moved to a module like dmd.driver? These functions are useless for other backends.

(Saying that, however, the compiler module won't be shared code).

static assert(0, "OS not supported yet.");

addDefaultVersionIdentifiers();
printPredefinedVersions();
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure that we want to call printPredefinedVersions here at all?
After all, this is the frontend for DMD as a library code.

@wilzbach
Copy link
Contributor

wilzbach commented Jan 7, 2018

@wilzbach I addressed the issues. I think we're good to go. I had to add -J../res to the parser and lexer library builds otherwise the tests would fail

You shouldn't need to add -J../res - this means that your parser.a now imports doc.d.
See also:

#7534 (comment)
#7534 (comment)

Shouldn't this be moved to a module like dmd.driver? These functions are useless for other backends.

dmd.driver sounds a bit misleading. How about mars.compiler, mars.versions or compiler/mars.d?

@andralex
Copy link
Member

@WalterBright ok with you?

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.

see merge conflict

}
}
=======
>>>>>>> Move addDefaultVersionIdentifiers to frontend.d
Copy link
Member

Choose a reason for hiding this comment

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

looks like some conflict made it into the pr

static if (TARGET_WINDOS)
{
VersionCondition.addPredefinedGlobalIdent("Windows");
global.params.isWindows = true;
Copy link
Member

Choose a reason for hiding this comment

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

This line should really not be here. "Setting predefined identifiers" and "setting the target platform in global" should be in different functions.

VersionCondition.addPredefinedGlobalIdent("D_Version2");
VersionCondition.addPredefinedGlobalIdent("all");

if (global.params.cpu >= CPU.sse2)
Copy link
Member

Choose a reason for hiding this comment

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

Note how this section is using global to set versions, whereas the previous section used TARGET to set it. Using TARGET to set global should be in a separate function, then this function should rely only on global to set versions.

Copy link
Member

Choose a reason for hiding this comment

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

Furthermore, instead of accessing global as a global variable, consider passing a const reference to it to the function.

}
else
{
static assert(0, "fix this");
Copy link
Member

Choose a reason for hiding this comment

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

Fixing a static assert failure is implied, so the message adds no value. "unsupported target" might be better.

@RazvanN7
Copy link
Contributor Author

Moving those functions to compiler.d is not a good idea. globals.d (which is part of the parser library) imports compiler.d. Moving these functions to compiler.d will introduce semantic dependencies to the parser library. Closing this PR until I will come up with a better solution.

@RazvanN7 RazvanN7 closed this Jan 26, 2018
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.

7 participants