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

New Error Code Framework #2468

Merged
merged 1 commit into from
Jul 28, 2023

Conversation

MahadMuhammad
Copy link
Contributor

@MahadMuhammad MahadMuhammad commented Jul 25, 2023

Updated ErrorCode Framework

There is no need to add check for wrong error codes, as it was automatically handled by Enum class.

  • Fixes Improve ErrorCode framework #2452

  • Converted from ErrorCode Struct to class.

  • Updated make_description accordingly.

  • Updated make_url accordingly.

  • Updated ErrorCode calling function.

Currently, there are some obsolete error codes which are not emitted by rustc. I was added them in the class, with comment, to keep consistency with rustc. The error codes which are rustc uses are all in this file https://github.com/rust-lang/rust/blob/master/compiler/rustc_error_codes/src/error_codes.rs.

Error Codes which are no longer emitted by rustc are :

E0001
E0002
E0007
E0009
E0014
E0073
E0074
E0087
E0088
E0089
E0090
E0110
E0136
E0137
E0139
E0154
E0162
E0165
E0192
E0193
E0205
E0208
E0211
E0243
E0244
E0251
E0256
E0263
E0281
E0297
E0301
E0302
E0303
E0312
E0329
E0383
E0386
E0387
E0388
E0389
E0398
E0439
E0447
E0448
E0477
E0482
E0495
E0497
E0504
E0523
E0595
E0619
E0632
E0633
E0660
E0661
E0662
E0663
E0664
E0665
E0668
E0669
E0671
E0687
E0688
E0759
E0760
E0772

The error codes which are emitted by rustc are :

E0004
E0005
E0010
E0013
E0015
E0023
E0025
E0026
E0027
E0029
E0030
E0033
E0034
E0038
E0040
E0044
E0045
E0046
E0049
E0050
E0053
E0054
E0055
E0057
E0059
E0060
E0061
E0062
E0063
E0067
E0069
E0070
E0071
E0072
E0075
E0076
E0077
E0080
E0081
E0084
E0091
E0092
E0093
E0094
E0106
E0107
E0109
E0116
E0117
E0118
E0119
E0120
E0121
E0124
E0128
E0130
E0131
E0132
E0133
E0138
E0152
E0158
E0161
E0164
E0170
E0178
E0183
E0184
E0185
E0186
E0191
E0195
E0197
E0198
E0199
E0200
E0201
E0203
E0204
E0206
E0207
E0210
E0212
E0214
E0220
E0221
E0222
E0223
E0224
E0225
E0226
E0227
E0228
E0229
E0230
E0231
E0232
E0252
E0253
E0254
E0255
E0259
E0260
E0261
E0262
E0264
E0267
E0268
E0271
E0275
E0276
E0277
E0282
E0283
E0284
E0307
E0308
E0309
E0310
E0311
E0316
E0317
E0320
E0321
E0322
E0323
E0324
E0325
E0326
E0328
E0364
E0365
E0366
E0367
E0368
E0369
E0370
E0371
E0373
E0374
E0375
E0376
E0377
E0378
E0379
E0380
E0381
E0382
E0384
E0390
E0391
E0392
E0393
E0399
E0401
E0403
E0404
E0405
E0407
E0408
E0409
E0411
E0412
E0415
E0416
E0422
E0423
E0424
E0425
E0426
E0428
E0429
E0430
E0431
E0432
E0433
E0434
E0435
E0436
E0437
E0438
E0445
E0446
E0449
E0451
E0452
E0453
E0454
E0455
E0457
E0458
E0459
E0460
E0461
E0462
E0463
E0464
E0466
E0468
E0469
E0472
E0476
E0478
E0491
E0492
E0493
E0496
E0498
E0499
E0500
E0501
E0502
E0503
E0505
E0506
E0507
E0508
E0509
E0510
E0511
E0512
E0514
E0515
E0516
E0517
E0518
E0519
E0520
E0521
E0522
E0524
E0525
E0527
E0528
E0529
E0530
E0531
E0532
E0533
E0534
E0535
E0536
E0537
E0538
E0539
E0541
E0542
E0543
E0544
E0545
E0546
E0547
E0549
E0550
E0551
E0552
E0554
E0556
E0557
E0559
E0560
E0561
E0562
E0565
E0566
E0567
E0568
E0569
E0570
E0571
E0572
E0573
E0574
E0575
E0576
E0577
E0578
E0579
E0580
E0581
E0582
E0583
E0584
E0585
E0586
E0587
E0588
E0589
E0590
E0591
E0592
E0593
E0594
E0596
E0597
E0599
E0600
E0601
E0602
E0603
E0604
E0605
E0606
E0607
E0608
E0609
E0610
E0614
E0615
E0616
E0617
E0618
E0620
E0621
E0622
E0623
E0624
E0625
E0626
E0627
E0628
E0631
E0634
E0635
E0636
E0637
E0638
E0639
E0640
E0641
E0642
E0643
E0644
E0646
E0647
E0648
E0657
E0658
E0659
E0666
E0667
E0670
E0689
E0690
E0691
E0692
E0693
E0695
E0696
E0697
E0698
E0699
E0700
E0701
E0703
E0704
E0705
E0706
E0708
E0710
E0711
E0712
E0713
E0714
E0715
E0716
E0717
E0718
E0719
E0720
E0722
E0724
E0725
E0726
E0727
E0728
E0729
E0730
E0731
E0732
E0733
E0734
E0735
E0736
E0737
E0739
E0740
E0741
E0742
E0743
E0744
E0745
E0746
E0747
E0748
E0749
E0750
E0751
E0752
E0753
E0754
E0755
E0756
E0757
E0758
E0761
E0762
E0763
E0764
E0765
E0766
E0767
E0768
E0769
E0770
E0771
E0773
E0774
E0775
E0776
E0777
E0778
E0779
E0780
E0781
E0782
E0783
E0784
E0785
E0786
E0787
E0788
E0789
E0790
E0791
E0792
E0793
E0794

@MahadMuhammad MahadMuhammad force-pushed the error-code-framework branch 2 times, most recently from c0145de to b06be4d Compare July 25, 2023 14:54
@P-E-P P-E-P requested review from CohenArthur and P-E-P July 26, 2023 09:24
gcc/rust/rust-diagnostics.h Outdated Show resolved Hide resolved
@P-E-P P-E-P added the diagnostic diagnostic static analysis label Jul 26, 2023
@MahadMuhammad MahadMuhammad force-pushed the error-code-framework branch 2 times, most recently from 6306980 to 89dd433 Compare July 26, 2023 12:19
Copy link
Member

@P-E-P P-E-P left a comment

Choose a reason for hiding this comment

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

LGTM, great work!

Copy link
Member

@CohenArthur CohenArthur 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! Thank you, good work @MahadMuhammad !

gcc/rust/rust-diagnostics.h Outdated Show resolved Hide resolved
gcc/rust/rust-diagnostics.h Outdated Show resolved Hide resolved
gcc/rust/rust-diagnostics.cc Outdated Show resolved Hide resolved

const char *m_str;
static std::unordered_map<ErrorCode,const char *> ErrorCodeString = {
Copy link
Member

Choose a reason for hiding this comment

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

...this:

Suggested change
static std::unordered_map<ErrorCode,const char *> ErrorCodeString = {
static std::unordered_map<ErrorCode, char *> ErrorCodeString = {

also I would suggest renaming the table to error_code_strings

@MahadMuhammad MahadMuhammad force-pushed the error-code-framework branch 2 times, most recently from 34244a3 to 42a31b3 Compare July 27, 2023 14:42
gcc/rust/error_codes.incl Outdated Show resolved Hide resolved
@CohenArthur
Copy link
Member

@MahadMuhammad please keep the changes simple for now - I think we should look at using the error_codes.incl file later, in a different PR

Updated ErrorCode struct to enum class to enforce proper
error codes, similiar to rustc. For converting the enum
to the respective error code, I used a map and updated
make_description & make_url function accordingly and
also removes the memory leak from the previous frame-
work. Also, added macro to safely convert the enum
number to string.

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (Intrinsics::compile):
	Formatted according to enum class.
	* checks/errors/rust-feature-gate.cc (FeatureGate::gate): likewise.
	* checks/errors/rust-unsafe-checker.cc (check_unsafe_call): likewise.
	* hir/rust-ast-lower-base.cc (struct_field_name_exists): likewise.
	* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): likewise.
	* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path):
	likewise.
	* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): likewise.
	(PatternDeclaration::add_new_binding): likewise.
	* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): likewise.
	* resolve/rust-ast-verify-assignee.h: likewise.
	* rust-diagnostics.cc: updated make_desc & url function for enum class.
	* rust-diagnostics.h (struct ErrorCode): removed struct to switch to enum.
	(enum class): Switched from errorcode struct to enum class.
	(XSTR): Macro for converting enum to string.
	(STR): macro Used by XSTR for converting to string.
	(ERROR_CODE): macro used by map for check.
	(TABLE_TO_MAP): macro used by map for check
	* typecheck/rust-casts.cc (TypeCastRules::emit_cast_error):
	Formatted according to enum class.
	* typecheck/rust-hir-path-probe.h: likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise.
	* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
	likewise.
	(TypeCheckImplItemWithTrait::visit): likewise.
	* typecheck/rust-hir-type-check-item.cc: likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): likewise.
	(emit_invalid_field_error): likewise.
	* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): likewise.
	* typecheck/rust-tyty-call.cc (emit_unexpected_argument_error): likewise.
	(TypeCheckCallExpr::visit): likewise.
	* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args):
	likewise.
	* typecheck/rust-tyty.cc (BaseType::bounds_compatible): likewise.

Signed-off-by: Muhammad Mahad <[email protected]>
Copy link
Member

@CohenArthur CohenArthur 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 to me! Thank you!

@CohenArthur CohenArthur added this pull request to the merge queue Jul 28, 2023
Merged via the queue into Rust-GCC:master with commit b4d1406 Jul 28, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis enhancement
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Improve ErrorCode framework
3 participants