Skip to content

Commit

Permalink
lint for boxed true types and bool types under fields mask
Browse files Browse the repository at this point in the history
  • Loading branch information
hrissan authored and Brat-vseznamus committed Jul 12, 2024
1 parent 9505f03 commit 64baf1b
Show file tree
Hide file tree
Showing 29 changed files with 609 additions and 96 deletions.
14 changes: 8 additions & 6 deletions cmd/tlgen/main2.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func parseFlags(opt *tlcodegen.Gen2Options) {
"treat all warnings as errors")
flag.BoolVar(&opt.Verbose, "v", false,
"verbose mode that prints debug info")
flag.BoolVar(&opt.PrintDiff, "print-diff", false,
"prints diff of outdir contents before and after generating")
flag.BoolVar(&opt.SplitInternal, "split-internal", false,
"generated code will be split into independent packages (in a simple word: speeds up compilation)")

Expand Down Expand Up @@ -92,17 +94,17 @@ func run(opt tlcodegen.Gen2Options) {
log.Println(err.Error())
}
if opt.Language == "" {
log.Printf("TL Linter Failed")
log.Printf("TL Linter Failed") // do not check Verbose
} else {
log.Printf("TL Generation Failed")
log.Printf("TL Generation Failed") // do not check Verbose
}
os.Exit(1)
return
}
if opt.Language == "" {
log.Printf("TL Linter Success")
log.Printf("TL Linter Success") // do not check Verbose
} else {
log.Printf("TL Generation Success")
log.Printf("TL Generation Success") // do not check Verbose
}
}

Expand Down Expand Up @@ -146,7 +148,7 @@ func runMain(opt *tlcodegen.Gen2Options) error {
}
if opt.TLOPath != "" {
if opt.Verbose {
log.Print("generating tlo file")
log.Print("generating TLO file...")
}
s, err := fullAst.GenerateTLO(uint32(opt.SchemaTimestamp))
if err != nil {
Expand All @@ -173,7 +175,7 @@ func runMain(opt *tlcodegen.Gen2Options) error {
}
if opt.CanonicalFormPath != "" {
if opt.Verbose {
log.Print("generating file with combinators in canonical form")
log.Print("generating file with combinators in canonical form,,,")
}
var buf bytes.Buffer
fullAst.WriteGenerate2TL(&buf)
Expand Down
266 changes: 261 additions & 5 deletions internal/tlcodegen/combined_tl_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,40 @@

package tlcodegen

import (
"fmt"
"sort"
)

// All compatibility code that will be removed after some fixes to TL itself

func EnableWarningsUnionNamespaceSkipLegacy(conNamespace string, typeNamespace string) bool {
type legacyPair struct {
conName string
fieldName string
}

var legacyExceptions []legacyPair // use it to populate this file with content of combined tl

func LegacyPrintGlobalMap() {
sort.Slice(legacyExceptions, func(i, j int) bool {
if legacyExceptions[i].conName != legacyExceptions[j].conName {
return legacyExceptions[i].conName < legacyExceptions[j].conName
}
return legacyExceptions[i].fieldName < legacyExceptions[j].fieldName
})

for _, v := range legacyExceptions {
fmt.Printf(` if conFullName == %q && fieldName == %q {
return true
}
`, v.conName, v.fieldName)
}
if len(legacyExceptions) != 0 {
fmt.Printf("--- Total %d exceptions\n", len(legacyExceptions))
}
}

func LegacyEnableWarningsUnionNamespaceSkip(conNamespace string, typeNamespace string) bool {
if conNamespace == "messagesLong" && typeNamespace == "messages" {
return true
}
Expand All @@ -34,7 +65,7 @@ func EnableWarningsUnionNamespaceSkipLegacy(conNamespace string, typeNamespace s
return false
}

func EnableWarningsSimpleTypeNameSkipLegacy(conFullName string) bool {
func LegacyEnableWarningsSimpleTypeNameSkip(conFullName string) bool {
if conFullName == "healthLoyalty.tmpGetCatalogResultOk" {
return true
}
Expand Down Expand Up @@ -125,11 +156,12 @@ func EnableWarningsSimpleTypeNameSkipLegacy(conFullName string) bool {
return false
}

func EnableWarningsUnionNamePrefixSkipLegacy(conName string, typePrefix string, typeSuffix string) bool {
// too many of them, impractical
func LegacyEnableWarningsUnionNamePrefixSkip(conName string, typePrefix string, typeSuffix string) bool {
return true // skip all warnings for now
}

func EnableWarningsUnionNameExactSkipLegacy(conFullName string) bool {
func LegacyEnableWarningsUnionNameExactSkip(conFullName string) bool {
if conFullName == "engine.queryResult" {
return true
}
Expand Down Expand Up @@ -158,6 +190,230 @@ func EnableWarningsUnionNameExactSkipLegacy(conFullName string) bool {
return false
}

func GenerateUnusedNatTemplates(conFullName string) bool {
func LegacyGenerateUnusedNatTemplates(conFullName string) bool {
return conFullName == "rpcInvokeReqExtra" || conFullName == "rpcReqResultExtra"
}

func LegacyAllowTrueBoxed(conFullName string, fieldName string) bool {
if conFullName == "genericModel.predict" && fieldName == "need_results_float" {
return true
}
if conFullName == "gopusher2.apnsPush" && fieldName == "is_voip" {
return true
}
if conFullName == "storage2.namespacePolicyBlocksCreation" && fieldName == "enable_blocks_creation" {
return true
}
if conFullName == "urlBoss.impParams" && fieldName == "keepAspectRatio" {
return true
}
if conFullName == "urlBoss.impParams" && fieldName == "proxy" {
return true
}
if conFullName == "urlBoss2.impParams" && fieldName == "keepAspectRatio" {
return true
}
if conFullName == "urlBoss2.impParams" && fieldName == "proxy" {
return true
}
if conFullName == "urlBoss2.routingParams" && fieldName == "randomSeed" {
return true
}
// below is goldmaster, we keep it to test generated code for this case
if conFullName == "useTrue" && fieldName == "b" {
return true
}
if conFullName == "useTrue" && fieldName == "d" {
return true
}
return false
}

func LegacyAllowBoolFieldsmask(conFullName string, fieldName string) bool {
if conFullName == "adsLalProcessing.processing" && fieldName == "is_deleted" {
return true
}
if conFullName == "adsLalProcessing.startProcessing" && fieldName == "use_apps" {
return true
}
if conFullName == "adsLalProcessing.startProcessing" && fieldName == "use_keywords" {
return true
}
if conFullName == "audiofpgen.genToPMCEx" && fieldName == "allow_short" {
return true
}
if conFullName == "audiofpgen.genToPMCEx" && fieldName == "delete_after_gen" {
return true
}
if conFullName == "blockchainNftCli.getNftDataRequestItem" && fieldName == "img_update" {
return true
}
if conFullName == "ch_proxy.params" && fieldName == "as_post" {
return true
}
if conFullName == "donutLevels.getResponse" && fieldName == "can_add" {
return true
}
if conFullName == "messages.keyboard" && fieldName == "inline" {
return true
}
if conFullName == "messages.keyboard" && fieldName == "one_time" {
return true
}
if conFullName == "messages.setPeerNotificationsSettings" && fieldName == "muted" {
return true
}
if conFullName == "messagesChat.setNotificationsStatus" && fieldName == "is_push_muted" {
return true
}
if conFullName == "messagesChatLong.changeChatMembers" && fieldName == "response_idlong" {
return true
}
if conFullName == "messagesChatLong.setNotificationsStatus" && fieldName == "is_push_muted" {
return true
}
if conFullName == "messagesLong.setFolderNotificationsSettings" && fieldName == "muted" {
return true
}
if conFullName == "messagesLong.setPeerNotificationsSettings" && fieldName == "muted" {
return true
}
if conFullName == "news2.joinedNews" && fieldName == "hidden_by_privacy" {
return true
}
if conFullName == "news2.modifiedNewsEntry" && fieldName == "hidden_by_privacy" {
return true
}
if conFullName == "news2.typeSettings" && fieldName == "deleted" {
return true
}
if conFullName == "news2.typeSettings" && fieldName == "non_std_lengths" {
return true
}
if conFullName == "news2.typeSettings" && fieldName == "normalize_id_lengths" {
return true
}
if conFullName == "online.setFriendOnlineExtraTyped" && fieldName == "invisible_mode" {
return true
}
if conFullName == "sandbox.attachProcessSettings" && fieldName == "store_stats" {
return true
}
if conFullName == "sandbox.createProcessSettings" && fieldName == "store_stats" {
return true
}
if conFullName == "sandbox.storeResultSettings" && fieldName == "store_stderr" {
return true
}
if conFullName == "sandbox.storeResultSettings" && fieldName == "store_stdout" {
return true
}
if conFullName == "searchService.searchMarket" && fieldName == "has_video" {
return true
}
if conFullName == "service.adsTargAdEngineInfo" && fieldName == "user_ad_has_click" {
return true
}
if conFullName == "socket.operateResponse" && fieldName == "closed" {
return true
}
if conFullName == "storage2Impl.engineState" && fieldName == "too_many_uploads" {
return true
}
if conFullName == "targ.ad" && fieldName == "enabled" {
return true
}
if conFullName == "targ.ad" && fieldName == "result_active" {
return true
}
if conFullName == "targ.ad" && fieldName == "schedule_active" {
return true
}
if conFullName == "targ.ad" && fieldName == "suspended" {
return true
}
if conFullName == "targ.adCampaign" && fieldName == "enabled" {
return true
}
if conFullName == "targ.banner" && fieldName == "enabled" {
return true
}
if conFullName == "targ.lal" && fieldName == "is_user_scores_fill_finished" {
return true
}
if conFullName == "targ.searchAdsFilter" && fieldName == "enabled_status" {
return true
}
if conFullName == "targ.searchAdsFilter" && fieldName == "suspended_status" {
return true
}
if conFullName == "targ.user" && fieldName == "has_photo" {
return true
}
if conFullName == "targ.user" && fieldName == "hidden" {
return true
}
if conFullName == "targ.user" && fieldName == "is_online" {
return true
}
if conFullName == "targ.user" && fieldName == "online_invisible" {
return true
}
if conFullName == "targ.user" && fieldName == "pays_money" {
return true
}
if conFullName == "targ.user" && fieldName == "uses_apps" {
return true
}
if conFullName == "targ.userAdApplyViewOptions" && fieldName == "use_for_predictions" {
return true
}
if conFullName == "targLong.user" && fieldName == "has_photo" {
return true
}
if conFullName == "targLong.user" && fieldName == "hidden" {
return true
}
if conFullName == "targLong.user" && fieldName == "is_online" {
return true
}
if conFullName == "targLong.user" && fieldName == "online_invisible" {
return true
}
if conFullName == "targLong.user" && fieldName == "pays_money" {
return true
}
if conFullName == "targLong.user" && fieldName == "uses_apps" {
return true
}
if conFullName == "targUser.adDetails" && fieldName == "is_fake" {
return true
}
if conFullName == "targUser.campaignDetails" && fieldName == "is_fake" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "is_blocking" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "is_enabled" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "is_persistent" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "is_staging" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "move_to_queue_begin_on_retry" {
return true
}
if conFullName == "wall.searchV2" && fieldName == "reverse" {
return true
}
// below is goldmaster, we keep it to test generated code for this case
if conFullName == "useTrue" && fieldName == "e" {
return true
}
// legacyExceptions = append(legacyExceptions, legacyPair{conName: conFullName, fieldName: fieldName})
return false
}
14 changes: 13 additions & 1 deletion internal/tlcodegen/test/gen/goldmaster.tlo.json
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@
"left": {
"type": "tls.combinatorLeft",
"value": {
"args_num": 5,
"args_num": 6,
"args": [
{
"id": "fm",
Expand Down Expand Up @@ -1883,6 +1883,18 @@
"name": 1072550713
}
}
},
{
"id": "e",
"flags": 4,
"exist_var_num": 0,
"exist_var_bit": 2,
"type": {
"type": "tls.typeExpr",
"value": {
"name": 621535874
}
}
}
]
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 64baf1b

Please sign in to comment.