-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC] Check types validity in the service graph at compile time - for currently loaded classes only #27744
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
Labels
DependencyInjection
DX
DX = Developer eXperience (anything that improves the experience of using Symfony)
RFC
RFC = Request For Comments (proposals about features that you want to be discussed)
Comments
Will my build process be slower? Yes. Does it guarantee a more stable run-time or even stop the build process and let me know I made a mistake? For sure! I think this would be worth implementing. |
I don't know if that's possible, but we could also try running this pass in a dedicated test case! |
alcalyn
added a commit
to alcalyn/symfony
that referenced
this issue
Jun 29, 2018
alcalyn
added a commit
to alcalyn/symfony
that referenced
this issue
Jul 3, 2018
alcalyn
added a commit
to alcalyn/symfony
that referenced
this issue
Jul 3, 2018
alcalyn
added a commit
to alcalyn/symfony
that referenced
this issue
Jul 4, 2018
alcalyn
added a commit
to alcalyn/symfony
that referenced
this issue
Jul 9, 2018
alcalyn
added a commit
to alcalyn/symfony
that referenced
this issue
Jul 9, 2018
Why not a new command that does this and that people can add to their CI? |
GuilhemN
pushed a commit
to GuilhemN/symfony
that referenced
this issue
Jun 28, 2019
GuilhemN
pushed a commit
to GuilhemN/symfony
that referenced
this issue
Jun 28, 2019
GuilhemN
pushed a commit
to GuilhemN/symfony
that referenced
this issue
Oct 2, 2019
nicolas-grekas
pushed a commit
that referenced
this issue
Oct 2, 2019
nicolas-grekas
added a commit
that referenced
this issue
Nov 4, 2019
…ces wiring matches type declarations (alcalyn, GuilhemN, nicolas-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [DI] Add compiler pass and command to check that services wiring matches type declarations | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27744 | License | MIT | Doc PR | PR replacing #27825. It adds a `lint:container` command asserting the type hints used in your code are correct. Commits ------- 8230a15 Make it really work on real apps 4b3e9d4 Fix comments, improve the feature a6292b9 [DI] Add compiler pass to check arguments type hint
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
DependencyInjection
DX
DX = Developer eXperience (anything that improves the experience of using Symfony)
RFC
RFC = Request For Comments (proposals about features that you want to be discussed)
Uh oh!
There was an error while loading. Please reload this page.
While wiring services, nothing prevents one from doing mistakes and break type hints, e.g. injecting a
Foo
object into an incompatibleBarInterface
-hinted argument.When this happens, the error is discovered at runtime. A common practice to detect this before prod is to create a smoke test that instantiates all services and does nothing else. This should work even better with the new test container in 4.1. Maybe something we could add to the MakerBundle? Of course, this strategy doesn't work for lazy services / locators / iterators. Not sure about false-positives also.
We're not verifying these references at compile-time because we do not want to load all PHP classes, as doing so takes time. Also because doing the verification itself might slow down the compilation too much and hurt DX.
Yet, I think we could still have a compiler pass that does these checks. In order to make it affordable, it would have a mode where it would check references only for currently loaded classes/interfaces, using
class|interface_exists()
withfalse
as 2nd argument, and maybeopcache_is_script_cached()
also.If the overhead of checking only the types (but not loading the code) is low enough, we could enable this pass by default in the dev env.
Worth a try?
The text was updated successfully, but these errors were encountered: